Ejb3Configuration.addPackage() 未找到实体
我想在创建 EntityManagerFactory 时以编程方式添加已知的 JPA 实体。 所以我有这个序列(Hibernate 3.6)
Ejb3Configuration ejbConf = new Ejb3Configuration();
ejbConf.configure("TestPU", null);
ejbConf.addPackage("org.jboss.jawabot.irc.ent");
ejbConf.addPackage("org.jboss.jawabot.irc.model");
emf = ejbConf.buildEntityManagerFactory();
我还尝试在configure()之前调用addPackage()。 添加包就好了。 但是,Hibernate 找不到实体。当我坚持下去时,我得到:
未知实体:org.jboss.jawabot.irc.model.IrcMessage
出了什么问题?如何让 Hbernate 识别这些包中的实体?
谢谢, Ondra
更新:该项目是此处。
有点混乱,因为我正在尝试一些技巧。
请注意,来自应用程序“核心”模块(jar)的实体将被拾取。
I want to add known JPA entities programatically when creating EntityManagerFactory.
So I have this sequence (Hibernate 3.6)
Ejb3Configuration ejbConf = new Ejb3Configuration();
ejbConf.configure("TestPU", null);
ejbConf.addPackage("org.jboss.jawabot.irc.ent");
ejbConf.addPackage("org.jboss.jawabot.irc.model");
emf = ejbConf.buildEntityManagerFactory();
I also tried calling addPackage()'s before configure().
Adding packages is fine.
However, Hibernate does not find the entities. When I persist it, I get:
Unknown entity: org.jboss.jawabot.irc.model.IrcMessage
What's wrong? How do I make Hbernate recognize entities from those packages?
Thanks,
Ondra
Update: The project is here.
A bit messy because I am trying few tricks in that.
And note, entities from the "core" module (jar) of the app are picked up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是,addPackage() 的目的只是告诉 Hibernate 考虑给定包的注释,而不是加载它的实体。
更多信息,
Ejb3Configuration
将在 4.0 中被弃用,取而代之的是EntityManagerFactoryBuilder
,请参阅 https://hibernate.onjira.com/browse/HHH-6159。The anwser is, the purpose of
addPackage()
is only to tell Hibernate to take given package's annotations into account, not to load it's Entities.More,
Ejb3Configuration
will be deprecated for 4.0 in favor ofEntityManagerFactoryBuilder
, see https://hibernate.onjira.com/browse/HHH-6159 .