以编程方式访问JPA
是否可以通过Java API访问的信息?
MySchema
我想通过JPA API或EclipseLink API阅读模式“MySchema”,这是我使用的实现。
类似于:entityManager.getDefaults()。getSchema(); 可以投射或使用任何EclipseLink类,这对此很好。
谢谢
调试一段时间后,我找到了一个访问实体模式的解决方案。
EntityType entity = emf.getMetamodel().entity(MyEntity.class); EntityTypeImpl entityTypeImpl = (EntityTypeImpl) entity; ClassDescriptor descriptor = entityTypeImpl.getDescriptor(); String schema = descriptor.getDefaultTable().getTableQualifier();
寻找更简单,更好的方式来访问信息! 非常感谢。
我知道这是一个老问题,但这里有一个更简单的方法来获取表名:
MyEntity.class.getAnnotation(javax.persistence.Entity.class).name();
之前的回复对我不起作用。 这是我发现的工作:
String schema = em.unwrap(JpaEntityManager.class).getServerSession().getDescriptor(MyClass.class).getTables().get(0).getTableQualifier();