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.
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,
Ejb3Configurationwill be deprecated for 4.0 in favor ofEntityManagerFactoryBuilder, see https://hibernate.onjira.com/browse/HHH-6159 .