Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Re: Manually creating persistence.xml or hbm.xml
Re: Manually creating persistence.xml or hbm.xml [message #514636] Tue, 16 February 2010 08:08 Go to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Lemao,
See comments inline.

btw, Teneo is supported on the main EMF newsgroup which I added in the cc.

gr. Martin

Lemao wrote:
> I have a somewhat large EMF model where I want to persist a subset of
> them using Teneo. Some of these persitent classes are somewhat
> independent and so easily made persistent with Teneo. However, I have a
> bunch of other EClasses that need to be partially persisted to the
> database if at all.
>
> 1) The first problem I am facing is that base EClass are considered top
> level entities even though their own purpose is for a proper in-memory
> abstraction. I am assuming that @MappedSubclass will solve this although
> I wasnt able to verify due to the next issue.
MT>> Yes @MappedSuperclass should solve this.
>
> 2) The next problem is that Teneo is, as expected, traversing all
> references in my model to things I dont want to persist. In some cases I
> dont want to persist a whole EClass and in some cases I dont want to
> persist a few references. Looking at the code I noticed that the
> top-level entity resolution takes into account the transient EMF
> property, but since my models are also written to files, I dont have the
> luxury of turning my EClasses or the specific references transient. I
> then came across adding @Transient annotation to EClass. After I added
> @Transient to all the EClasses I didnt want persisted to the db I still
> seems to traverse all references even though the EClasses have the
> @Transient annotation.
MT>> This should work as you expected. Did you regenerate the java source code after setting the annotation on the EClass?
You can also add the @Transient annotation in the EStructuralFeature to prevent persisting that specific feature.

>
> 3) I then thought that a good way to do this would be to take the
> mappings entirely into my hands. I grabbed a dump of the mappings
> generated by Teneo (I had a fairly independent part of the model
> persisted in Teneo), set the required PersistenceOptions to read from a
> file instead of auto generating and then manually added the mappings for
> the EClasses I wanted to persist and only the attributes/references I
> needed. Here I got exception in the EMFTuplizer. Is this possible, i.e.
> craft the mapping in Hibernate HBM or JPA persistence.xml entirely by hand?
> At this point I am not sure what to do and wondering if I am missing
> something obvious here?
MT>> Hmm, you got a dump of the mappings created by Teneo and then added your own eclasses, were those eclasses not
already present in the mapping?
What exception did you get?

>
> Thanks in advance,
>
> In addition, would it be possible to write my mappings directly in
> Hibernate hbm or JPA persistence.xml without using the mapping generation?
MT>> It can be done, but the easiest strategy is to let Teneo generate an initial mapping, store that in a hbm file and
then adapt this mapping manually if needed.
At runtime you need to use the Teneo runtime layer because Teneo adds logic to Hibernate to handle EMF specifics
(bi-directional lists, containment etc.)

>


--

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: Manually creating persistence.xml or hbm.xml [message #514845 is a reply to message #514636] Tue, 16 February 2010 20:37 Go to previous messageGo to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
Martin,
Here is my reply I posted in EMF Technologies by mistake.

Thanks for the comments.

> 2) The next problem is that Teneo is, as expected, traversing all
> references in my model to things I dont want to persist. In some cases I
> dont want to persist a whole EClass and in some cases I dont want to
> persist a few references. Looking at the code I noticed that the
> top-level entity resolution takes into account the transient EMF
> property, but since my models are also written to files, I dont have the
> luxury of turning my EClasses or the specific references transient. I
> then came across adding @Transient annotation to EClass. After I added
> @Transient to all the EClasses I didnt want persisted to the db I still
> seems to traverse all references even though the EClasses have the
> @Transient annotation.
MT>> This should work as you expected. Did you regenerate the java source code after setting the annotation on the EClass?
You can also add the @Transient annotation in the EStructuralFeature to prevent persisting that specific feature.

L>> It seems that there is a first pass that traverses all the EMF references reaching things like EMF XSD Schema, which is not annotated. I was expecting that @Transient on the opposite EClass or on the EReference would preclude Teneo from traversing the dependencies at all, but it seems that the traversal still happens and barfs if it reaches an EClass that is not annotated such as the EMFXSD Schema EClass. My problem is that I am forced to have persistence only on a parallel model without any references to things like EMF XSD.

> 3) I then thought that a good way to do this would be to take the
> mappings entirely into my hands. I grabbed a dump of the mappings
> generated by Teneo (I had a fairly independent part of the model
> persisted in Teneo), set the required PersistenceOptions to read from a
> file instead of auto generating and then manually added the mappings for
> the EClasses I wanted to persist and only the attributes/references I
> needed. Here I got exception in the EMFTuplizer. Is this possible, i.e.
> craft the mapping in Hibernate HBM or JPA persistence.xml entirely by hand?
> At this point I am not sure what to do and wondering if I am missing
> something obvious here?
MT>> Hmm, you got a dump of the mappings created by Teneo and then added your own eclasses, were those eclasses not
already present in the mapping? What exception did you get?

L>> Because of issue 2) I didnt add the extra EPackages for these to the HbDataStore and was hoping I could manually add the hbm mapping for the EClass. But after looking at the code, I noticed that it assumes that all persistent EClasses in the HBM to be processed are present in PAnnotatedModel. The exception was a NPE or something like that in EMFTuplizer after getting a null HbDataStore for the PersistentClass.

> In addition, would it be possible to write my mappings directly in
> Hibernate hbm or JPA persistence.xml without using the mapping generation?
MT>> It can be done, but the easiest strategy is to let Teneo generate an initial mapping, store that in a hbm file and
then adapt this mapping manually if needed.
At runtime you need to use the Teneo runtime layer because Teneo adds logic to Hibernate to handle EMF specifics
(bi-directional lists, containment etc.)

L>> I also read in the documentation that there is way to specify the persistence mapping using an external xml file. I do like this approach since it decouples the model from the mapping completely in spite of the added initial effort to craft the mapping (maybe alleviated by letting Teneo initially generate the mapping). However, this custom mapping xml adds another layer to understand and sometimes we are constrained by it if it doesnt expose all the features found in HBM for instance. I would be quite happier to write the mapping directly in HBM with the proper tuplizer elements, and what not, sprinkled in the xml. At least I am dealing with a mapping I understand and is extensively documented on the web.
After taking a peek at the code, it seems that it is not possible to plug the Teneo runtime (tuplizer, collection adapters, etc) directly into hibernate hbm xml since the code assumes a PAnnotatedModel created, which implies traversing and processing EPackage and the issue found in 2). It would be great if these two layers (annotation and mapping generation, vs teneo runtime) were more independent so I could use just the runtime if I wanted. If this is not the case, would you have a simple example of how to create a plain HBM leveraging just the Teneo runtime?

Of course, a solution for 2) would also help here.

thanks,
Re: Manually creating persistence.xml or hbm.xml [message #514847 is a reply to message #514636] Tue, 16 February 2010 20:14 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Lemao,
See my comments inline.

gr. Martin

Lemao wrote:
> Hi Martin,
> Thanks for the comments!
>
>> 2) The next problem is that Teneo is, as expected, traversing all
>> references in my model to things I dont want to persist. In some cases
>> I dont want to persist a whole EClass and in some cases I dont want to
>> persist a few references. Looking at the code I noticed that the
>> top-level entity resolution takes into account the transient EMF
>> property, but since my models are also written to files, I dont have
>> the luxury of turning my EClasses or the specific references
>> transient. I then came across adding @Transient annotation to EClass.
>> After I added @Transient to all the EClasses I didnt want persisted to
>> the db I still seems to traverse all references even though the
>> EClasses have the @Transient annotation.
> MT>> This should work as you expected. Did you regenerate the java
> source code after setting the annotation on the EClass?
> You can also add the @Transient annotation in the EStructuralFeature to
> prevent persisting that specific feature.
>
> L>> It seems that there is a first pass that traverses all the EMF
> references reaching things like EMF XSD Schema, which is not annotated.
> I was expecting that @Transient on the opposite EClass or on the
> EReference would preclude Teneo from traversing the dependencies at all,
> but it seems that the traversal still happens and barfs if it reaches an
> EClass that is not annotated such as the EMFXSD Schema EClass. My
> problem is that I am forced to have persistence only on a parallel model
> without any references to things like EMF XSD.
MT>> Yes I agree that it makes sense to operate as you say (do not traverse if transient).
Currently the transient annotation is partially handled in the annotator and partially in
the hbm generation. Which causes this behavior. Can you enter a feature request for this?
I am currently busy with integrating Teneo in the Eclipse continuous build system. But probably
next week or so I can take a look at this.

>
>> 3) I then thought that a good way to do this would be to take the
>> mappings entirely into my hands. I grabbed a dump of the mappings
>> generated by Teneo (I had a fairly independent part of the model
>> persisted in Teneo), set the required PersistenceOptions to read from
>> a file instead of auto generating and then manually added the mappings
>> for the EClasses I wanted to persist and only the
>> attributes/references I needed. Here I got exception in the
>> EMFTuplizer. Is this possible, i.e. craft the mapping in Hibernate HBM
>> or JPA persistence.xml entirely by hand?
>> At this point I am not sure what to do and wondering if I am missing
>> something obvious here?
> MT>> Hmm, you got a dump of the mappings created by Teneo and then added
> your own eclasses, were those eclasses not already present in the
> mapping? What exception did you get?
>
> L>> Because of issue 2) I didnt add the extra EPackages for these to the
> HbDataStore and was hoping I could manually add the hbm mapping for the
> EClass. But after looking at the code, I noticed that it assumes that
> all persistent EClasses in the HBM to be processed are present in
> PAnnotatedModel. The exception was a NPE or something like that in
> EMFTuplizer after getting a null HbDataStore for the PersistentClass.
MT>> Can you attach the stacktrace to the feature request? NPE's are not nice!
>
>> In addition, would it be possible to write my mappings directly in
>> Hibernate hbm or JPA persistence.xml without using the mapping
>> generation?
> MT>> It can be done, but the easiest strategy is to let Teneo generate
> an initial mapping, store that in a hbm file and then adapt this mapping
> manually if needed.
> At runtime you need to use the Teneo runtime layer because Teneo adds
> logic to Hibernate to handle EMF specifics (bi-directional lists,
> containment etc.)
>
> L>> I also read in the documentation that there is way to specify the
> persistence mapping using an external xml file. I do like this approach
> since it decouples the model from the mapping completely in spite of the
> added initial effort to craft the mapping (maybe alleviated by letting
> Teneo initially generate the mapping). However, this custom mapping xml
> adds another layer to understand and sometimes we are constrained by it
> if it doesnt expose all the features found in HBM for instance. I would
> be quite happier to write the mapping directly in HBM with the proper
> tuplizer elements, and what not, sprinkled in the xml. At least I am
> dealing with a mapping I understand and is extensively documented on the
> web.
> After taking a peek at the code, it seems that it is not possible to
> plug the Teneo runtime (tuplizer, collection adapters, etc) directly
> into hibernate hbm xml since the code assumes a PAnnotatedModel created,
> which implies traversing and processing EPackage and the issue found in
> 2). It would be great if these two layers (annotation and mapping
> generation, vs teneo runtime) were more independent so I could use just
> the runtime if I wanted. If this is not the case, would you have a
> simple example of how to create a plain HBM leveraging just the Teneo
> runtime?
MT>> I would say that if you use the mapping file option that the pamodel is not needed. But it is a bit chicken/egg as
to get an initial hbm it needs to traverse the pamodel. So I would say that if the hbm file is there the Pamodel is not
needed. If so this can/should be changed afaics.

>
> Of course, a solution for 2) would also help here.
>
> 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: Manually creating persistence.xml or hbm.xml [message #514849 is a reply to message #514847] Tue, 16 February 2010 20:45 Go to previous messageGo to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
Hi Martin,

L>>Enhancement submitted: #302993. I think that the NPE happened when using Hibernate Configuration directly without the Teneo runtime. So dont think it is really a concern.

> L>> I also read in the documentation that there is way to specify the
> persistence mapping using an external xml file. I do like this approach
> since it decouples the model from the mapping completely in spite of the
> added initial effort to craft the mapping (maybe alleviated by letting
> Teneo initially generate the mapping). However, this custom mapping xml
> adds another layer to understand and sometimes we are constrained by it
> if it doesnt expose all the features found in HBM for instance. I would
> be quite happier to write the mapping directly in HBM with the proper
> tuplizer elements, and what not, sprinkled in the xml. At least I am
> dealing with a mapping I understand and is extensively documented on the
> web.
> After taking a peek at the code, it seems that it is not possible to
> plug the Teneo runtime (tuplizer, collection adapters, etc) directly
> into hibernate hbm xml since the code assumes a PAnnotatedModel created,
> which implies traversing and processing EPackage and the issue found in
> 2). It would be great if these two layers (annotation and mapping
> generation, vs teneo runtime) were more independent so I could use just
> the runtime if I wanted. If this is not the case, would you have a
> simple example of how to create a plain HBM leveraging just the Teneo
> runtime?
MT>> I would say that if you use the mapping file option that the pamodel is not needed. But it is a bit chicken/egg as
to get an initial hbm it needs to traverse the pamodel. So I would say that if the hbm file is there the Pamodel is not
needed. If so this can/should be changed afaics.

L>> Upon further investigation, this is what I found out (may be obvious to you, but worse case scenario you will ignore).

1. HbEntityDataStore.initialize() is called
1.1. HbEntityDataStore.mapModel(), which uses the hbm file I provided
1.2. HbDataStore.initializeDataStore() is called
1.2.1. setInterceptor() is called
1.2.1.1. getEntityNameStrategy() is called
1.2.1.2. getPaModel() is called causing the PaModel to be constructed and the full mode traversal

It seems that anything after HbEntityDataStore.mapModel() should no longer depend on getPaModel() when reading from an existing HBM xml.

fyi: I am using EMF 2.5 and Teneo 1.1.2.

[Updated on: Tue, 16 February 2010 21:07]

Report message to a moderator

Re: Manually creating persistence.xml or hbm.xml [message #514864 is a reply to message #514849] Tue, 16 February 2010 18:06 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Lemao,
Your reply shows as empty in my news reader.

gr. Martin

Lemao wrote:
>


--

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: Manually creating persistence.xml or hbm.xml [message #514891 is a reply to message #514864] Wed, 17 February 2010 02:31 Go to previous messageGo to next message
Lemao  is currently offline Lemao Friend
Messages: 48
Registered: December 2009
Member
Hi Martin, here it goes again....


Hi Martin,

L>>Enhancement submitted: #302993. I think that the NPE happened when using Hibernate Configuration directly without the Teneo runtime. So dont think it is really a concern.

> L>> I also read in the documentation that there is way to specify the
> persistence mapping using an external xml file. I do like this approach
> since it decouples the model from the mapping completely in spite of the
> added initial effort to craft the mapping (maybe alleviated by letting
> Teneo initially generate the mapping). However, this custom mapping xml
> adds another layer to understand and sometimes we are constrained by it
> if it doesnt expose all the features found in HBM for instance. I would
> be quite happier to write the mapping directly in HBM with the proper
> tuplizer elements, and what not, sprinkled in the xml. At least I am
> dealing with a mapping I understand and is extensively documented on the
> web.
> After taking a peek at the code, it seems that it is not possible to
> plug the Teneo runtime (tuplizer, collection adapters, etc) directly
> into hibernate hbm xml since the code assumes a PAnnotatedModel created,
> which implies traversing and processing EPackage and the issue found in
> 2). It would be great if these two layers (annotation and mapping
> generation, vs teneo runtime) were more independent so I could use just
> the runtime if I wanted. If this is not the case, would you have a
> simple example of how to create a plain HBM leveraging just the Teneo
> runtime?
MT>> I would say that if you use the mapping file option that the pamodel is not needed. But it is a bit chicken/egg as
to get an initial hbm it needs to traverse the pamodel. So I would say that if the hbm file is there the Pamodel is not
needed. If so this can/should be changed afaics.

L>> Upon further investigation, this is what I found out (may be obvious to you, but worse case scenario you will ignore).

1. HbEntityDataStore.initialize() is called
1.1. HbEntityDataStore.mapModel(), which uses the hbm file I provided
1.2. HbDataStore.initializeDataStore() is called
1.2.1. setInterceptor() is called
1.2.1.1. getEntityNameStrategy() is called
1.2.1.2. getPaModel() is called causing the PaModel to be constructed and the full mode traversal

It seems that anything after HbEntityDataStore.mapModel() should no longer depend on getPaModel() when reading from an existing HBM xml.

fyi: I am using EMF 2.5 and Teneo 1.1.2.
Re: Manually creating persistence.xml or hbm.xml [message #514907 is a reply to message #514891] Wed, 17 February 2010 07:14 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Lemao,
I won't ignore :-) it, I will look at the execution path you outlined in more detail when I solve the bugzilla.

gr. Martin

Lemao wrote:
> Hi Martin, here it goes again....
>
>
> Hi Martin,
> L>>Enhancement submitted: #302993. I think that the NPE happened when
> using Hibernate Configuration directly without the Teneo runtime. So
> dont think it is really a concern.
>
>> L>> I also read in the documentation that there is way to specify the
>> persistence mapping using an external xml file. I do like this
>> approach since it decouples the model from the mapping completely in
>> spite of the added initial effort to craft the mapping (maybe
>> alleviated by letting Teneo initially generate the mapping). However,
>> this custom mapping xml adds another layer to understand and sometimes
>> we are constrained by it if it doesnt expose all the features found in
>> HBM for instance. I would be quite happier to write the mapping
>> directly in HBM with the proper tuplizer elements, and what not,
>> sprinkled in the xml. At least I am dealing with a mapping I
>> understand and is extensively documented on the web.
>> After taking a peek at the code, it seems that it is not possible to
>> plug the Teneo runtime (tuplizer, collection adapters, etc) directly
>> into hibernate hbm xml since the code assumes a PAnnotatedModel
>> created, which implies traversing and processing EPackage and the
>> issue found in 2). It would be great if these two layers (annotation
>> and mapping generation, vs teneo runtime) were more independent so I
>> could use just the runtime if I wanted. If this is not the case, would
>> you have a simple example of how to create a plain HBM leveraging just
>> the Teneo runtime?
> MT>> I would say that if you use the mapping file option that the
> pamodel is not needed. But it is a bit chicken/egg as to get an initial
> hbm it needs to traverse the pamodel. So I would say that if the hbm
> file is there the Pamodel is not needed. If so this can/should be
> changed afaics.
>
> L>> Upon further investigation, this is what I found out (may be obvious
> to you, but worse case scenario you will ignore).
> 1. HbEntityDataStore.initialize() is called
> 1.1. HbEntityDataStore.mapModel(), which uses the hbm file I provided
> 1.2. HbDataStore.initializeDataStore() is called
> 1.2.1. setInterceptor() is called
> 1.2.1.1. getEntityNameStrategy() is called
> 1.2.1.2. getPaModel() is called causing the PaModel to be constructed
> and the full mode traversal
>
> It seems that anything after HbEntityDataStore.mapModel() should no
> longer depend on getPaModel() when reading from an existing HBM xml.
>
> fyi: I am using EMF 2.5 and Teneo 1.1.2.
>


--

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
Previous Topic:[EMF Databinding] Need an ObservableMapContentProvider?
Next Topic:[CDO] Manipulating Subgraph of object in CDOEditor
Goto Forum:
  


Current Time: Fri Apr 26 11:43:13 GMT 2024

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

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

Back to the top