Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Load mapping file at "runtime"

Hi Christian,

Is it possible to have multiple persitence units that have the same entities, but different orm xml files that override the mappings and just select the persistence unit that has the override you need.

It is possible to alter the underlying EclipseLink metadata after your peristence unit is created, but you need to be careful because there is quite alot of code that runs at initialization time to make sure everything is consistence. Changing the field a BasicMapping maps to should be fairlyl easy, but if you get into changing relationships mappings or mappings within InheritanceHierarchies, you will have to be quite careful.

org.eclipse.persistence.jpa.JpaHelper has a getServerSession() method that can get our underlying session. Session has a project and project has a list of mappings that can be acquired by name. Changing the mappings is a matter of calling the appropriate methods on the various mappings you get back.

-Tom

Christian August Michelsen wrote:
I'm having a wee bit trouble figuring out if and how I can specify a one or more mapping-files based on some business logic when I create my entitymanager (or before).

I basically have an entity where I have a string I'd like to map to different kinds of columns (read only) based on some information I have before I create my EMF and EM, but not at build/compile time.

So can one feed EclipseLink with the mapping files in any other way than through the persistence.xml-file?


Some background:
The reason I want to do this is that I have an ecommerce app that I'm connecting to. Now this web app has several different payment solutions whereas they pretty much all create a one or more new columns in the database. These of course have different names...

Now people usually only just use one of these payment solutions, so I thought I'd support this by having some generic strings in my entity class that maps to whatever column(s) the plugin adds. This way I don't have to maintain different entities of an order just to support different payment providers for instance.




Back to the top