Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Having multiple orm.xml
Having multiple orm.xml [message #523470] Fri, 26 March 2010 14:05 Go to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi,
I have a question, is it possible to work with multiple orm.xml files? So get EclipseLink to read both?

Some background, I am generating the orm.xml file. But I want a developer to be able to override or add mappings in
another orm.xml file (which is not overwritten at next generation-actions).
So both xml files can have a mapping for an entity (the first mapping will be quite empty).

Is this possible, so can EclipseLink read both xml files and combine the mapping for one entity?

Thanks!

--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Having multiple orm.xml [message #523799 is a reply to message #523470] Mon, 29 March 2010 12:38 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun Smith
Messages: 197
Registered: July 2009
Senior Member
Hi Martin,

You can have any number of mapping files, but with different names.
"META-INF/orm.xml" is automatically found. Other files need to be
listed in the persistence.xml. However the JPA spec requires that an
entity be mapped only in one file (but could have annotations). So the
developer would have to edit the generated orm.xml in order to
augment/edit the mappings you're generating.

Given you're taking a model-centric approach wouldn't the developer
edit the model and regenerate the mappings?

Shaun

On 26/3/2010 10:05 AM, Martin Taal wrote:
> Hi,
> I have a question, is it possible to work with multiple orm.xml files?
> So get EclipseLink to read both?
>
> Some background, I am generating the orm.xml file. But I want a
> developer to be able to override or add mappings in another orm.xml file
> (which is not overwritten at next generation-actions).
> So both xml files can have a mapping for an entity (the first mapping
> will be quite empty).
>
> Is this possible, so can EclipseLink read both xml files and combine the
> mapping for one entity?
>
> Thanks!
>


--
Oracle <http://www.oracle.com>
Shaun Smith | Principal Product Manager
Phone: +19055023094
Oracle Server Technologies, Oracle TopLink
ORACLE Canada | 110 Matheson Boulevard West, Suite 100, Mississauga,
Ontario | L5R 3P4
Green Oracle <http://www.oracle.com/commitment> Oracle is committed to
developing practices and products that help protect the environment
Re: Having multiple orm.xml [message #523871 is a reply to message #523799] Mon, 29 March 2010 16:53 Go to previous messageGo to next message
Shaun Smith is currently offline Shaun Smith
Messages: 197
Registered: July 2009
Senior Member
Martin,

In my initial response I went into "spec compliant mode" and focused on
a standard way to achieve what you want. I should have added that you
can use eclipselink-orm.xml to go beyond the spec to override the
orm.xml settings:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Overriding_Annotations_with_eclipselink-orm.xml_File

So you could have annotated classes overridden by orm.xml overridden by
eclipselink-orm.xml.

--Shaun

On 29/3/2010 8:38 AM, Shaun Smith wrote:
> Hi Martin,
>
> You can have any number of mapping files, but with different names.
> "META-INF/orm.xml" is automatically found. Other files need to be listed
> in the persistence.xml. However the JPA spec requires that an entity be
> mapped only in one file (but could have annotations). So the developer
> would have to edit the generated orm.xml in order to augment/edit the
> mappings you're generating.
>
> Given you're taking a model-centric approach wouldn't the developer edit
> the model and regenerate the mappings?
>
> Shaun
>
> On 26/3/2010 10:05 AM, Martin Taal wrote:
>> Hi,
>> I have a question, is it possible to work with multiple orm.xml files?
>> So get EclipseLink to read both?
>>
>> Some background, I am generating the orm.xml file. But I want a
>> developer to be able to override or add mappings in another orm.xml file
>> (which is not overwritten at next generation-actions).
>> So both xml files can have a mapping for an entity (the first mapping
>> will be quite empty).
>>
>> Is this possible, so can EclipseLink read both xml files and combine the
>> mapping for one entity?
>>
>> Thanks!
>>
>
>


--
Oracle <http://www.oracle.com>
Shaun Smith | Principal Product Manager
Phone: +19055023094
Oracle Server Technologies, Oracle TopLink
ORACLE Canada | 110 Matheson Boulevard West, Suite 100, Mississauga,
Ontario | L5R 3P4
Green Oracle <http://www.oracle.com/commitment> Oracle is committed to
developing practices and products that help protect the environment
Re: Having multiple orm.xml [message #533481 is a reply to message #523871] Fri, 14 May 2010 08:33 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Shaun,
I am looking at this topic again. Some more questions:
- Can I tell EclipseLink to look at other locations than META-INF for the persistence.xml? Even outside of the classpath?
- Can I have multiple persistence.xml files (with a slightly different name) and let EclipseLink read them all? For
example by telling EclipseLink to look in a specific folder and use all the files in the folder? (I saw the
ECLIPSELINK_PERSISTENCE_XML = "eclipselink.persistencexml" property, but I am not sure if it allows a folder)
- Can orm.xml files also be located outside of the classpath? I mean if I set a direct absolute file path in the
persistence.xml?

gr. Martin

Shaun Smith wrote:
> Martin,
>
> In my initial response I went into "spec compliant mode" and focused on
> a standard way to achieve what you want. I should have added that you
> can use eclipselink-orm.xml to go beyond the spec to override the
> orm.xml settings:
> http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Overriding_Annotations_with_eclipselink-orm.xml_File
>
>
> So you could have annotated classes overridden by orm.xml overridden by
> eclipselink-orm.xml.
>
> --Shaun
>
> On 29/3/2010 8:38 AM, Shaun Smith wrote:
>> Hi Martin,
>>
>> You can have any number of mapping files, but with different names.
>> "META-INF/orm.xml" is automatically found. Other files need to be listed
>> in the persistence.xml. However the JPA spec requires that an entity be
>> mapped only in one file (but could have annotations). So the developer
>> would have to edit the generated orm.xml in order to augment/edit the
>> mappings you're generating.
>>
>> Given you're taking a model-centric approach wouldn't the developer edit
>> the model and regenerate the mappings?
>>
>> Shaun
>>
>> On 26/3/2010 10:05 AM, Martin Taal wrote:
>>> Hi,
>>> I have a question, is it possible to work with multiple orm.xml files?
>>> So get EclipseLink to read both?
>>>
>>> Some background, I am generating the orm.xml file. But I want a
>>> developer to be able to override or add mappings in another orm.xml file
>>> (which is not overwritten at next generation-actions).
>>> So both xml files can have a mapping for an entity (the first mapping
>>> will be quite empty).
>>>
>>> Is this possible, so can EclipseLink read both xml files and combine the
>>> mapping for one entity?
>>>
>>> Thanks!
>>>
>>
>>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Having multiple orm.xml [message #533729 is a reply to message #533481] Sun, 16 May 2010 10:51 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Shaun,
For the record, I found a solution by generating a persistence.xml for each test model and inside the persistence.xml
refer to the specific orm file for that test model (which is also generated). Then when creating the entity manager
factory creation method I set the "eclipselink.persistencexml" to point to the persistence.xml for that test model.

This works fine.

gr. Martin

Martin Taal wrote:
> Hi Shaun,
> I am looking at this topic again. Some more questions:
> - Can I tell EclipseLink to look at other locations than META-INF for
> the persistence.xml? Even outside of the classpath?
> - Can I have multiple persistence.xml files (with a slightly different
> name) and let EclipseLink read them all? For example by telling
> EclipseLink to look in a specific folder and use all the files in the
> folder? (I saw the ECLIPSELINK_PERSISTENCE_XML =
> "eclipselink.persistencexml" property, but I am not sure if it allows a
> folder)
> - Can orm.xml files also be located outside of the classpath? I mean if
> I set a direct absolute file path in the persistence.xml?
>
> gr. Martin
>
> Shaun Smith wrote:
>> Martin,
>>
>> In my initial response I went into "spec compliant mode" and focused
>> on a standard way to achieve what you want. I should have added that
>> you can use eclipselink-orm.xml to go beyond the spec to override the
>> orm.xml settings:
>> http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Overriding_Annotations_with_eclipselink-orm.xml_File
>>
>>
>> So you could have annotated classes overridden by orm.xml overridden
>> by eclipselink-orm.xml.
>>
>> --Shaun
>>
>> On 29/3/2010 8:38 AM, Shaun Smith wrote:
>>> Hi Martin,
>>>
>>> You can have any number of mapping files, but with different names.
>>> "META-INF/orm.xml" is automatically found. Other files need to be listed
>>> in the persistence.xml. However the JPA spec requires that an entity be
>>> mapped only in one file (but could have annotations). So the developer
>>> would have to edit the generated orm.xml in order to augment/edit the
>>> mappings you're generating.
>>>
>>> Given you're taking a model-centric approach wouldn't the developer edit
>>> the model and regenerate the mappings?
>>>
>>> Shaun
>>>
>>> On 26/3/2010 10:05 AM, Martin Taal wrote:
>>>> Hi,
>>>> I have a question, is it possible to work with multiple orm.xml files?
>>>> So get EclipseLink to read both?
>>>>
>>>> Some background, I am generating the orm.xml file. But I want a
>>>> developer to be able to override or add mappings in another orm.xml
>>>> file
>>>> (which is not overwritten at next generation-actions).
>>>> So both xml files can have a mapping for an entity (the first mapping
>>>> will be quite empty).
>>>>
>>>> Is this possible, so can EclipseLink read both xml files and combine
>>>> the
>>>> mapping for one entity?
>>>>
>>>> Thanks!
>>>>
>>>
>>>
>>
>>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Having multiple orm.xml [message #555777 is a reply to message #533729] Sat, 28 August 2010 15:19 Go to previous message
Joel Rosi-Schwartz is currently offline Joel Rosi-Schwartz
Messages: 624
Registered: July 2009
Location: London. England
Senior Member
Hi,

I have a slightly different slant on this question, but as it is in the same vain I think it is useful if I continue this thread.

I am using OSGi + EMF + Teneo + Eclipselink. I will be creating multiple EMF model plugins, each of which will generate an EMF model bundle with the generated entities. Each model will be saved to its own Resource. Teneo will be used to generate the orm.xml. I have created a service bundle named ResourceLocator that contains the code that does the EMF <==> Eclispelink stuff.
   public Resource locate(final EClass contentType, final EAttribute feature, final String value, final String persistenceUnitName) {
      // create EclipseLink URI for saving/loading library model in/from database
      final String query = EclipseLinkURIUtil.createContentsEqualQuery(contentType, feature, value);
      final URI uri = EclipseLinkURIUtil.createEclipseLinkURI(persistenceUnitName, query);

      // save library model instance in database
      final ResourceSet resourceSet = new ResourceSetImpl();

      resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("eclipselink", new EclipseLinkResourceFactoryImpl());
      resourceSet.getLoadOptions().putAll(getTestPersistenceUnitProperties());

      final Resource resource = resourceSet.getResource(uri, true);

      return resource;
   }


Now I have the question: Where do I put all of the orm.xml files? Seems I have a few options:


  1. leave them in the model bundles and add imports to all of them
  2. move them to the service bundle, rename them and reference them in persistence.xml
  3. try to achieve this with bundle fragments


I do not like the first, because in principle the service should not have to know anything about its clients. I dislike the second a bit less, but essentially it has the same design flaw. The third would be the least in intrusive as the coupling is done at runtime by the client, but I am not certain if it will fly.

Any thoughts or advice on this? This has to be a common scenario with EMF <==> Eclipselink mapping for anything but the most trivial model, but I have not seen any discussions around it.

Many thanks,
Joel

Previous Topic:Querydsl
Next Topic:switch to session.xml
Goto Forum:
  


Current Time: Fri Oct 31 21:42:57 GMT 2014

Powered by FUDForum. Page generated in 0.22740 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software