• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple persistance unit simultaneously, issue.  RSS feed

 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.
I have a doubt, regarding multiple persistence units. The unitName element specifies the name of the persistence unit, in the persistence.xml file. A persistence
unit is essentially a grouping of entities used in an application. It is ok. Let say I want to have multiple persistence units, so when I create EntityManager, specifying the unit I want, it will manage that classes.
So I should have persistence.xml file, like this :



So, when I get an EntityManager of persistence unit named GeneralUnit , it will be used for managing clases under that persistence unit, right?
If all this presumptions are ok, my question is :
"If I use property : , inside persistence-unit element, configuration, it means it will detect all @Entity classes. Do I need for each persistance context, to list a classes I want that particular EntityManager. to handle"?
Thanks!
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, or should I just create separate Ejb-jar for each persistence context, group of "stand alone" classes?
I mean, that my each .jar file, to contains its own classes, and one persistence.xml configuration file, with only one persistence-unit declared, related to the classes in that .jar?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Slobodan Erakovic wrote:Hi, or should I just create separate Ejb-jar for each persistence context, group of "stand alone" classes?
I mean, that my each .jar file, to contains its own classes, and one persistence.xml configuration file, with only one persistence-unit declared, related to the classes in that .jar?


Depends actually. If both those set of entities are independent then it makes sense to have 2 separate jar files, each with their own set of persistence unit configurations. It's much cleaner this way.

However, if you want to package them together in a single jar, you can still do it, like in your example. So you will have a single jar file with a single persistence.xml containing configurations for 2 separate persistence units. Then in each persistence unit, you will list the classes which are to be managed by that persistence unit.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you Jaikiran. I have figured out, that the best way is (because the packages of classes are completely independent) to have a separate ejb-jar, for each persistence unit. It is also the way I can dynamically add, new ejb-jar (persistent context), and app. server will perform "hot deployment".
I mean, that is much more "cleaner" way, to do so, instead of messing and "overweighting", single ejb-jar, and persistence context.
Thanks again!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!