访问JPA< persistence-unit-metadata>编程 [英] Access JPA <persistence-unit-metadata> programmatically

查看:96
本文介绍了访问JPA< persistence-unit-metadata>编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过Java API访问< persistence-unit-metadata> 中的信息?

is it possible to access the information in <persistence-unit-metadata> through Java API?

<persistence-unit-metadata>
    <persistence-unit-defaults>
        <schema>MySchema</schema>
    </persistence-unit-defaults>
</persistence-unit-metadata>

我想通过JPA API或EclipseLink API读取模式MySchema,这是实现我用。

I would like to read the schema "MySchema" via JPA API or EclipseLink API, which is the implementation I use.

类似于:entityManager.getDefaults()。getSchema();
可以投射或使用任何EclipseLink类,这对此很好。

Something like: entityManager.getDefaults().getSchema(); It's OK to cast or use any EclipseLink class, that's fine for this.

谢谢

推荐答案

调试一段时间后,我找到了一个访问实体模式的解决方案。

After debugging for a while I found a solution to access the schema of an entity.

EntityType<MyEntity> entity = emf.getMetamodel().entity(MyEntity.class);

EntityTypeImpl entityTypeImpl = (EntityTypeImpl) entity;        
ClassDescriptor descriptor =  entityTypeImpl.getDescriptor();

String schema = descriptor.getDefaultTable().getTableQualifier();

寻找更简单,更好的方式来访问信息!
非常感谢你。

Looking for an easier and better way to access the information! Thank you so much.

这篇关于访问JPA&lt; persistence-unit-metadata&gt;编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆