Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-dev] Loading multiple persistence.xml files

Hi, Tom.

You've nailed it.  Each persistence.xml is trying to create the same persistence unit ("default").  Is there a nice way to load 1 persistence unit from multiple orm.xml files?  I've seen some classloader tricks to accomplish this but don't want to head down that rabbit hole unless necessary.

Thanks,
Carl


On Wed, Dec 17, 2008 at 10:55, Tom Ware <tom.ware@xxxxxxxxxx> wrote:
Hi Carl,

 Are you using separate EntityManagers for each persistence unit?

 An EntityManager represents one persistence unit - when the EntityManagerFactory is created, you get it by persistence unit name.  Any EntityManager created by that factory will represent that persistence unit.

 The name of a persistence unit is specified in the persistence.xml and only one persistence.xml may be used to define a given persistence units.  It is an error to have multiple persistence.xml that define the same persistence unit and the behavior is undefined - I am not surprised that if you are doing this, you get the last one loaded.

 To access different persistence units, create an EntityManager for each.

-Tom

Carl Hall wrote:
I have a setup where multiple project come into a shared classloader.  Each project can have its own model files and thusly its own persistence.xml and orm.xml files.  When I create an EntityManager, I see in the logs that each persistence.xml file is found (3) and each orm.xml file loads with the expected entities.  When I try to query or persist using this EntityManager, only the entities from the lastly loaded persistence.xml is found.  Am I loading this correctly?  Am I trying to access things incorrectly?


------------------------------------------------------------------------

_______________________________________________
eclipselink-dev mailing list
eclipselink-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-dev
_______________________________________________
eclipselink-dev mailing list
eclipselink-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-dev


Back to the top