Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Association table not created for one-to-many EMF reference
[Teneo] Association table not created for one-to-many EMF reference [message #115219] Thu, 20 March 2008 22:35 Go to next message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
Hi Guys,

I noticed that some references in my data (persisted with Teneo) were null
when I reloaded them from the DB. I looked at the DB and found that I was
inexplicably missing one of the association tables. The offending
association is for the EMF-modeled type and reference
"WarfareSystem.dependencies". The corresponding entry in the auto-genned
hbm file is:

<list name="dependencies" lazy="true">
<key update="true" foreign-key="warfaresystem_dependencies">
<column name="`warfaresystem_dependencies_e_id`"
not-null="false" unique="false"/>
</key>
<list-index column="`warfaresystem_dependencies_idx`"/>
<one-to-many entity-name="WarfareSystem"/>
</list>

The relevant mapping info message that is printed to console during the
mapping is:

1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
WarfareSystem.dependencies -> warfaresystem

Note that I have an analagous reference for another type that is being
persisted correctly with it's own association table. The entry in the hbm
file is identical (modulo the name/type of the reference), and the info
message is:

1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
Step.outputsTo -> step_outputsto

Which I believe is correct. Any idea why this might happen to the
"dependencies" reference? Are there any other diagnostics I can perform to
get you more info?

Daniel
Re: [Teneo] Association table not created for one-to-many EMF reference [message #115233 is a reply to message #115219] Thu, 20 March 2008 22:49 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Daniel,
I think it is not a missing table (otherwise you would get a hibernate/sql error). Afaics the
association you are mentioning below is not persisted using a join table but using a foreign key in
the child table.
A cause for having null values in a list is that a child got deleted without removing it from the
list of the parent. For example if you just read the child from the db (and not the parent) and then
remove the child then hibernate won't update the indexes in the list. This results in a hole in the
indexes in the childs. When reading the contents of the list hibernate will place null values in the
list in the missing locations. You can check this out by looking in the db and see if values in the
warfaresystem_dependencies_idx column are correct (no missing values).

If this is the cause then there are two solutions:
- change your code so that when removing the child it is also removed from the parent
- change the mapping to a set/bag instead of a list, then the idx column is not present. This is
only possible if the order of the children is not important. See here for more info:
http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations

gr. Martin

Daniel Tuohy wrote:
> Hi Guys,
>
> I noticed that some references in my data (persisted with Teneo) were null
> when I reloaded them from the DB. I looked at the DB and found that I was
> inexplicably missing one of the association tables. The offending
> association is for the EMF-modeled type and reference
> "WarfareSystem.dependencies". The corresponding entry in the auto-genned
> hbm file is:
>
> <list name="dependencies" lazy="true">
> <key update="true" foreign-key="warfaresystem_dependencies">
> <column name="`warfaresystem_dependencies_e_id`"
> not-null="false" unique="false"/>
> </key>
> <list-index column="`warfaresystem_dependencies_idx`"/>
> <one-to-many entity-name="WarfareSystem"/>
> </list>
>
> The relevant mapping info message that is printed to console during the
> mapping is:
>
> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
> WarfareSystem.dependencies -> warfaresystem
>
> Note that I have an analagous reference for another type that is being
> persisted correctly with it's own association table. The entry in the hbm
> file is identical (modulo the name/type of the reference), and the info
> message is:
>
> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
> Step.outputsTo -> step_outputsto
>
> Which I believe is correct. Any idea why this might happen to the
> "dependencies" reference? Are there any other diagnostics I can perform to
> get you more info?
>
> Daniel
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #115247 is a reply to message #115233] Fri, 21 March 2008 01:52 Go to previous messageGo to next message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
OK. I think I may have finally uncovered the real problem

You're right about the association table. I had forgotten that I had added
an annotation for "Step.outputsTo" that (for whatever reason) induces an
association table. I did the same for the "Warfare.dependencies" reference
and it appears to have solved the problem for the object with the null
references. The annotation is:

<eclass name="WarfareSystem">
<property name="dependencies">
<many-to-many fetch="EAGER" target-entity="WarfareSystem">
<cascade>MERGE</cascade>
<cascade>PERSIST</cascade>
</many-to-many>
</property>
</eclass>

So it's the lazy loading that's the problem. Because the references aren't
actually null, they're just waiting for me to call system.getDependencies()
to be loaded from the DB.

This poses a problem, however. I'm trying to serialize the object from the
DB to a resource, and the EMF code doesn't do the nice thing and call
system.getDependencies(), it just tries to persist what's already in memory.
So I get the following error:

java.lang.NullPointerException
at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)

So there are two solutions:
1. I find some way (or petition the EMF guys) to make the EMF serialization
code call the appropriate methods to trigger hibernate to retrieve
referenced objects.
2. I eagerly load everything (which is essentially every reference in my
data model).

If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
eagerly load *everything*?


"Martin Taal" <mtaal@elver.org> wrote in message
news:fruplj$p6$1@build.eclipse.org...
> Hi Daniel,
> I think it is not a missing table (otherwise you would get a hibernate/sql
> error). Afaics the association you are mentioning below is not persisted
> using a join table but using a foreign key in the child table.
> A cause for having null values in a list is that a child got deleted
> without removing it from the list of the parent. For example if you just
> read the child from the db (and not the parent) and then remove the child
> then hibernate won't update the indexes in the list. This results in a
> hole in the indexes in the childs. When reading the contents of the list
> hibernate will place null values in the list in the missing locations. You
> can check this out by looking in the db and see if values in the
> warfaresystem_dependencies_idx column are correct (no missing values).
>
> If this is the cause then there are two solutions:
> - change your code so that when removing the child it is also removed from
> the parent
> - change the mapping to a set/bag instead of a list, then the idx column
> is not present. This is only possible if the order of the children is not
> important. See here for more info:
> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> Hi Guys,
>>
>> I noticed that some references in my data (persisted with Teneo) were
>> null when I reloaded them from the DB. I looked at the DB and found that
>> I was inexplicably missing one of the association tables. The offending
>> association is for the EMF-modeled type and reference
>> "WarfareSystem.dependencies". The corresponding entry in the auto-genned
>> hbm file is:
>>
>> <list name="dependencies" lazy="true">
>> <key update="true" foreign-key="warfaresystem_dependencies">
>> <column name="`warfaresystem_dependencies_e_id`"
>> not-null="false" unique="false"/>
>> </key>
>> <list-index column="`warfaresystem_dependencies_idx`"/>
>> <one-to-many entity-name="WarfareSystem"/>
>> </list>
>>
>> The relevant mapping info message that is printed to console during the
>> mapping is:
>>
>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>> WarfareSystem.dependencies -> warfaresystem
>>
>> Note that I have an analagous reference for another type that is being
>> persisted correctly with it's own association table. The entry in the
>> hbm file is identical (modulo the name/type of the reference), and the
>> info message is:
>>
>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>> Step.outputsTo -> step_outputsto
>>
>> Which I believe is correct. Any idea why this might happen to the
>> "dependencies" reference? Are there any other diagnostics I can perform
>> to get you more info?
>>
>> Daniel
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #115273 is a reply to message #115247] Fri, 21 March 2008 05:43 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I am not sure why the many-to-many solved your npe. Regarding lazy loading, even without going
through the getter the lazy loaded list should be automatically loaded when accessed (for example
through an iterator) and not have null values. Afaics null values in the list point to the problem I
described in my previous reply (holes in the list).

Regarding eager loading, there is this option: PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you
set this to true then it will eagerly load all containment lists.

gr. Martin

Daniel Tuohy wrote:
> OK. I think I may have finally uncovered the real problem
>
> You're right about the association table. I had forgotten that I had added
> an annotation for "Step.outputsTo" that (for whatever reason) induces an
> association table. I did the same for the "Warfare.dependencies" reference
> and it appears to have solved the problem for the object with the null
> references. The annotation is:
>
> <eclass name="WarfareSystem">
> <property name="dependencies">
> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
> <cascade>MERGE</cascade>
> <cascade>PERSIST</cascade>
> </many-to-many>
> </property>
> </eclass>
>
> So it's the lazy loading that's the problem. Because the references aren't
> actually null, they're just waiting for me to call system.getDependencies()
> to be loaded from the DB.
>
> This poses a problem, however. I'm trying to serialize the object from the
> DB to a resource, and the EMF code doesn't do the nice thing and call
> system.getDependencies(), it just tries to persist what's already in memory.
> So I get the following error:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>
> So there are two solutions:
> 1. I find some way (or petition the EMF guys) to make the EMF serialization
> code call the appropriate methods to trigger hibernate to retrieve
> referenced objects.
> 2. I eagerly load everything (which is essentially every reference in my
> data model).
>
> If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
> eagerly load *everything*?
>
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fruplj$p6$1@build.eclipse.org...
>> Hi Daniel,
>> I think it is not a missing table (otherwise you would get a hibernate/sql
>> error). Afaics the association you are mentioning below is not persisted
>> using a join table but using a foreign key in the child table.
>> A cause for having null values in a list is that a child got deleted
>> without removing it from the list of the parent. For example if you just
>> read the child from the db (and not the parent) and then remove the child
>> then hibernate won't update the indexes in the list. This results in a
>> hole in the indexes in the childs. When reading the contents of the list
>> hibernate will place null values in the list in the missing locations. You
>> can check this out by looking in the db and see if values in the
>> warfaresystem_dependencies_idx column are correct (no missing values).
>>
>> If this is the cause then there are two solutions:
>> - change your code so that when removing the child it is also removed from
>> the parent
>> - change the mapping to a set/bag instead of a list, then the idx column
>> is not present. This is only possible if the order of the children is not
>> important. See here for more info:
>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> Hi Guys,
>>>
>>> I noticed that some references in my data (persisted with Teneo) were
>>> null when I reloaded them from the DB. I looked at the DB and found that
>>> I was inexplicably missing one of the association tables. The offending
>>> association is for the EMF-modeled type and reference
>>> "WarfareSystem.dependencies". The corresponding entry in the auto-genned
>>> hbm file is:
>>>
>>> <list name="dependencies" lazy="true">
>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>> <column name="`warfaresystem_dependencies_e_id`"
>>> not-null="false" unique="false"/>
>>> </key>
>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>> <one-to-many entity-name="WarfareSystem"/>
>>> </list>
>>>
>>> The relevant mapping info message that is printed to console during the
>>> mapping is:
>>>
>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>> WarfareSystem.dependencies -> warfaresystem
>>>
>>> Note that I have an analagous reference for another type that is being
>>> persisted correctly with it's own association table. The entry in the
>>> hbm file is identical (modulo the name/type of the reference), and the
>>> info message is:
>>>
>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>> Step.outputsTo -> step_outputsto
>>>
>>> Which I believe is correct. Any idea why this might happen to the
>>> "dependencies" reference? Are there any other diagnostics I can perform
>>> to get you more info?
>>>
>>> Daniel
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #115299 is a reply to message #115273] Fri, 21 March 2008 21:04 Go to previous messageGo to next message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
So, in your estimation, there is no way EMF could be accessing those
references and not triggering lazy loading? I suspect that the references
are being retrieved using feature IDs, although I don't know that would make
a difference.

As far as the holes-in-the-list conjecture, I should mention that I'm
literally creating the object, persisting it, reloading it and attempting to
serialize to a resource. There is no adding to or removal from any list
references going on. If this were the case, then I shouldn't be seeing an
inconsistency between the in-memory and persisted representations, right?

"Martin Taal" <mtaal@elver.org> wrote in message
news:frvhu0$ha9$1@build.eclipse.org...
>I am not sure why the many-to-many solved your npe. Regarding lazy loading,
>even without going through the getter the lazy loaded list should be
>automatically loaded when accessed (for example through an iterator) and
>not have null values. Afaics null values in the list point to the problem I
>described in my previous reply (holes in the list).
>
> Regarding eager loading, there is this option:
> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true then
> it will eagerly load all containment lists.
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> OK. I think I may have finally uncovered the real problem
>>
>> You're right about the association table. I had forgotten that I had
>> added an annotation for "Step.outputsTo" that (for whatever reason)
>> induces an association table. I did the same for the
>> "Warfare.dependencies" reference and it appears to have solved the
>> problem for the object with the null references. The annotation is:
>>
>> <eclass name="WarfareSystem">
>> <property name="dependencies">
>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>> <cascade>MERGE</cascade>
>> <cascade>PERSIST</cascade>
>> </many-to-many>
>> </property>
>> </eclass>
>>
>> So it's the lazy loading that's the problem. Because the references
>> aren't actually null, they're just waiting for me to call
>> system.getDependencies() to be loaded from the DB.
>>
>> This poses a problem, however. I'm trying to serialize the object from
>> the DB to a resource, and the EMF code doesn't do the nice thing and call
>> system.getDependencies(), it just tries to persist what's already in
>> memory. So I get the following error:
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>
>> So there are two solutions:
>> 1. I find some way (or petition the EMF guys) to make the EMF
>> serialization code call the appropriate methods to trigger hibernate to
>> retrieve referenced objects.
>> 2. I eagerly load everything (which is essentially every reference in my
>> data model).
>>
>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
>> eagerly load *everything*?
>>
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:fruplj$p6$1@build.eclipse.org...
>>> Hi Daniel,
>>> I think it is not a missing table (otherwise you would get a
>>> hibernate/sql error). Afaics the association you are mentioning below is
>>> not persisted using a join table but using a foreign key in the child
>>> table.
>>> A cause for having null values in a list is that a child got deleted
>>> without removing it from the list of the parent. For example if you just
>>> read the child from the db (and not the parent) and then remove the
>>> child then hibernate won't update the indexes in the list. This results
>>> in a hole in the indexes in the childs. When reading the contents of the
>>> list hibernate will place null values in the list in the missing
>>> locations. You can check this out by looking in the db and see if values
>>> in the warfaresystem_dependencies_idx column are correct (no missing
>>> values).
>>>
>>> If this is the cause then there are two solutions:
>>> - change your code so that when removing the child it is also removed
>>> from the parent
>>> - change the mapping to a set/bag instead of a list, then the idx column
>>> is not present. This is only possible if the order of the children is
>>> not important. See here for more info:
>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>
>>> gr. Martin
>>>
>>> Daniel Tuohy wrote:
>>>> Hi Guys,
>>>>
>>>> I noticed that some references in my data (persisted with Teneo) were
>>>> null when I reloaded them from the DB. I looked at the DB and found
>>>> that I was inexplicably missing one of the association tables. The
>>>> offending association is for the EMF-modeled type and reference
>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>> auto-genned hbm file is:
>>>>
>>>> <list name="dependencies" lazy="true">
>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>> not-null="false" unique="false"/>
>>>> </key>
>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>> <one-to-many entity-name="WarfareSystem"/>
>>>> </list>
>>>>
>>>> The relevant mapping info message that is printed to console during the
>>>> mapping is:
>>>>
>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>> WarfareSystem.dependencies -> warfaresystem
>>>>
>>>> Note that I have an analagous reference for another type that is being
>>>> persisted correctly with it's own association table. The entry in the
>>>> hbm file is identical (modulo the name/type of the reference), and the
>>>> info message is:
>>>>
>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>> Step.outputsTo -> step_outputsto
>>>>
>>>> Which I believe is correct. Any idea why this might happen to the
>>>> "dependencies" reference? Are there any other diagnostics I can
>>>> perform to get you more info?
>>>>
>>>> Daniel
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #115314 is a reply to message #115299] Sat, 22 March 2008 10:08 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I agree that if you only do create, persist and reload that there should not be a hole-in-list
situation.
A few questions:
- Does it fail on the first element in the list?
- Are other parts of the list set?
- What class is the list?
- If it is one of the hibernate teneo list implementations, what does the isLoaded property say
(just before the npe happens)?

If you can make a (small) reproducible test then I can look at it also. You can send it to me
directly by email (mtaal_at_elver.org).

gr. Martin

Daniel Tuohy wrote:
> So, in your estimation, there is no way EMF could be accessing those
> references and not triggering lazy loading? I suspect that the references
> are being retrieved using feature IDs, although I don't know that would make
> a difference.
>
> As far as the holes-in-the-list conjecture, I should mention that I'm
> literally creating the object, persisting it, reloading it and attempting to
> serialize to a resource. There is no adding to or removal from any list
> references going on. If this were the case, then I shouldn't be seeing an
> inconsistency between the in-memory and persisted representations, right?
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:frvhu0$ha9$1@build.eclipse.org...
>> I am not sure why the many-to-many solved your npe. Regarding lazy loading,
>> even without going through the getter the lazy loaded list should be
>> automatically loaded when accessed (for example through an iterator) and
>> not have null values. Afaics null values in the list point to the problem I
>> described in my previous reply (holes in the list).
>>
>> Regarding eager loading, there is this option:
>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true then
>> it will eagerly load all containment lists.
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> OK. I think I may have finally uncovered the real problem
>>>
>>> You're right about the association table. I had forgotten that I had
>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>> induces an association table. I did the same for the
>>> "Warfare.dependencies" reference and it appears to have solved the
>>> problem for the object with the null references. The annotation is:
>>>
>>> <eclass name="WarfareSystem">
>>> <property name="dependencies">
>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>> <cascade>MERGE</cascade>
>>> <cascade>PERSIST</cascade>
>>> </many-to-many>
>>> </property>
>>> </eclass>
>>>
>>> So it's the lazy loading that's the problem. Because the references
>>> aren't actually null, they're just waiting for me to call
>>> system.getDependencies() to be loaded from the DB.
>>>
>>> This poses a problem, however. I'm trying to serialize the object from
>>> the DB to a resource, and the EMF code doesn't do the nice thing and call
>>> system.getDependencies(), it just tries to persist what's already in
>>> memory. So I get the following error:
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>
>>> So there are two solutions:
>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>> serialization code call the appropriate methods to trigger hibernate to
>>> retrieve referenced objects.
>>> 2. I eagerly load everything (which is essentially every reference in my
>>> data model).
>>>
>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
>>> eagerly load *everything*?
>>>
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:fruplj$p6$1@build.eclipse.org...
>>>> Hi Daniel,
>>>> I think it is not a missing table (otherwise you would get a
>>>> hibernate/sql error). Afaics the association you are mentioning below is
>>>> not persisted using a join table but using a foreign key in the child
>>>> table.
>>>> A cause for having null values in a list is that a child got deleted
>>>> without removing it from the list of the parent. For example if you just
>>>> read the child from the db (and not the parent) and then remove the
>>>> child then hibernate won't update the indexes in the list. This results
>>>> in a hole in the indexes in the childs. When reading the contents of the
>>>> list hibernate will place null values in the list in the missing
>>>> locations. You can check this out by looking in the db and see if values
>>>> in the warfaresystem_dependencies_idx column are correct (no missing
>>>> values).
>>>>
>>>> If this is the cause then there are two solutions:
>>>> - change your code so that when removing the child it is also removed
>>>> from the parent
>>>> - change the mapping to a set/bag instead of a list, then the idx column
>>>> is not present. This is only possible if the order of the children is
>>>> not important. See here for more info:
>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>
>>>> gr. Martin
>>>>
>>>> Daniel Tuohy wrote:
>>>>> Hi Guys,
>>>>>
>>>>> I noticed that some references in my data (persisted with Teneo) were
>>>>> null when I reloaded them from the DB. I looked at the DB and found
>>>>> that I was inexplicably missing one of the association tables. The
>>>>> offending association is for the EMF-modeled type and reference
>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>> auto-genned hbm file is:
>>>>>
>>>>> <list name="dependencies" lazy="true">
>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>> not-null="false" unique="false"/>
>>>>> </key>
>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>> </list>
>>>>>
>>>>> The relevant mapping info message that is printed to console during the
>>>>> mapping is:
>>>>>
>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>
>>>>> Note that I have an analagous reference for another type that is being
>>>>> persisted correctly with it's own association table. The entry in the
>>>>> hbm file is identical (modulo the name/type of the reference), and the
>>>>> info message is:
>>>>>
>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>> Step.outputsTo -> step_outputsto
>>>>>
>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>> perform to get you more info?
>>>>>
>>>>> Daniel
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #115367 is a reply to message #115314] Sat, 22 March 2008 20:31 Go to previous messageGo to next message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
1. Yes, it fails on the first element in the list.
2. Yes. There are four elements in the list, and the last one is set, the
first three are null.
3. The list is a HibernatePersistableEList.
4. isLoaded() returns "true"

I should also note that I am now seeing inconsistent behavior. Sometimes
the list for the object is full of the correct references, sometimes the
first three are null and only the last is set, and sometimes the list is
actually empty.

The object being persisted is very elaborate, and the object whose
references are corrupted is contained within the object I'm trying to
serialize. The JUnit test I am running is not complicated, it consists of
object creation, persistence, retrieval, and serialization (failing on
serialization when it gets to these references).

Unfortunately, it concerns a great deal of data and a large EMF model, so I
will have to consult my employer before I can commit to sending over a test
case. Does anything further oc

"Martin Taal" <mtaal@elver.org> wrote in message
news:fs2lrj$nbg$1@build.eclipse.org...
>I agree that if you only do create, persist and reload that there should
>not be a hole-in-list
> situation.
> A few questions:
> - Does it fail on the first element in the list?
> - Are other parts of the list set?
> - What class is the list?
> - If it is one of the hibernate teneo list implementations, what does the
> isLoaded property say (just before the npe happens)?
>
> If you can make a (small) reproducible test then I can look at it also.
> You can send it to me directly by email (mtaal_at_elver.org).
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> So, in your estimation, there is no way EMF could be accessing those
>> references and not triggering lazy loading? I suspect that the
>> references are being retrieved using feature IDs, although I don't know
>> that would make a difference.
>>
>> As far as the holes-in-the-list conjecture, I should mention that I'm
>> literally creating the object, persisting it, reloading it and attempting
>> to serialize to a resource. There is no adding to or removal from any
>> list references going on. If this were the case, then I shouldn't be
>> seeing an inconsistency between the in-memory and persisted
>> representations, right?
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:frvhu0$ha9$1@build.eclipse.org...
>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>> loading, even without going through the getter the lazy loaded list
>>> should be automatically loaded when accessed (for example through an
>>> iterator) and not have null values. Afaics null values in the list point
>>> to the problem I described in my previous reply (holes in the list).
>>>
>>> Regarding eager loading, there is this option:
>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>> then it will eagerly load all containment lists.
>>>
>>> gr. Martin
>>>
>>> Daniel Tuohy wrote:
>>>> OK. I think I may have finally uncovered the real problem
>>>>
>>>> You're right about the association table. I had forgotten that I had
>>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>>> induces an association table. I did the same for the
>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>> problem for the object with the null references. The annotation is:
>>>>
>>>> <eclass name="WarfareSystem">
>>>> <property name="dependencies">
>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>> <cascade>MERGE</cascade>
>>>> <cascade>PERSIST</cascade>
>>>> </many-to-many>
>>>> </property>
>>>> </eclass>
>>>>
>>>> So it's the lazy loading that's the problem. Because the references
>>>> aren't actually null, they're just waiting for me to call
>>>> system.getDependencies() to be loaded from the DB.
>>>>
>>>> This poses a problem, however. I'm trying to serialize the object from
>>>> the DB to a resource, and the EMF code doesn't do the nice thing and
>>>> call system.getDependencies(), it just tries to persist what's already
>>>> in memory. So I get the following error:
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>> at
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>> at
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>
>>>> So there are two solutions:
>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>> serialization code call the appropriate methods to trigger hibernate to
>>>> retrieve referenced objects.
>>>> 2. I eagerly load everything (which is essentially every reference in
>>>> my data model).
>>>>
>>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate
>>>> to eagerly load *everything*?
>>>>
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>> Hi Daniel,
>>>>> I think it is not a missing table (otherwise you would get a
>>>>> hibernate/sql error). Afaics the association you are mentioning below
>>>>> is not persisted using a join table but using a foreign key in the
>>>>> child table.
>>>>> A cause for having null values in a list is that a child got deleted
>>>>> without removing it from the list of the parent. For example if you
>>>>> just read the child from the db (and not the parent) and then remove
>>>>> the child then hibernate won't update the indexes in the list. This
>>>>> results in a hole in the indexes in the childs. When reading the
>>>>> contents of the list hibernate will place null values in the list in
>>>>> the missing locations. You can check this out by looking in the db and
>>>>> see if values in the warfaresystem_dependencies_idx column are correct
>>>>> (no missing values).
>>>>>
>>>>> If this is the cause then there are two solutions:
>>>>> - change your code so that when removing the child it is also removed
>>>>> from the parent
>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>> column is not present. This is only possible if the order of the
>>>>> children is not important. See here for more info:
>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> Hi Guys,
>>>>>>
>>>>>> I noticed that some references in my data (persisted with Teneo) were
>>>>>> null when I reloaded them from the DB. I looked at the DB and found
>>>>>> that I was inexplicably missing one of the association tables. The
>>>>>> offending association is for the EMF-modeled type and reference
>>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>>> auto-genned hbm file is:
>>>>>>
>>>>>> <list name="dependencies" lazy="true">
>>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>> not-null="false" unique="false"/>
>>>>>> </key>
>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>> </list>
>>>>>>
>>>>>> The relevant mapping info message that is printed to console during
>>>>>> the mapping is:
>>>>>>
>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>>
>>>>>> Note that I have an analagous reference for another type that is
>>>>>> being persisted correctly with it's own association table. The entry
>>>>>> in the hbm file is identical (modulo the name/type of the reference),
>>>>>> and the info message is:
>>>>>>
>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>> Step.outputsTo -> step_outputsto
>>>>>>
>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>> perform to get you more info?
>>>>>>
>>>>>> Daniel
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #115380 is a reply to message #115367] Sat, 22 March 2008 20:37 Go to previous messageGo to next message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
Sorry, I sent that prematurely. It was meant to end: "Does anything further
occur to you in light of the answers to your questions, or due to the
inconsistency in the contents of that list?"

I should also note that I see this inconsistency only when I recreate the DB
and persist the object each time I run the test. If I just load the object
from the same DB repeatedly, the behavior is consistent.

"Daniel Tuohy" <danielr2e@gmail.com> wrote in message
news:fs3q7l$j5r$1@build.eclipse.org...
> 1. Yes, it fails on the first element in the list.
> 2. Yes. There are four elements in the list, and the last one is set,
> the first three are null.
> 3. The list is a HibernatePersistableEList.
> 4. isLoaded() returns "true"
>
> I should also note that I am now seeing inconsistent behavior. Sometimes
> the list for the object is full of the correct references, sometimes the
> first three are null and only the last is set, and sometimes the list is
> actually empty.
>
> The object being persisted is very elaborate, and the object whose
> references are corrupted is contained within the object I'm trying to
> serialize. The JUnit test I am running is not complicated, it consists of
> object creation, persistence, retrieval, and serialization (failing on
> serialization when it gets to these references).
>
> Unfortunately, it concerns a great deal of data and a large EMF model, so
> I will have to consult my employer before I can commit to sending over a
> test case. Does anything further oc
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fs2lrj$nbg$1@build.eclipse.org...
>>I agree that if you only do create, persist and reload that there should
>>not be a hole-in-list
>> situation.
>> A few questions:
>> - Does it fail on the first element in the list?
>> - Are other parts of the list set?
>> - What class is the list?
>> - If it is one of the hibernate teneo list implementations, what does the
>> isLoaded property say (just before the npe happens)?
>>
>> If you can make a (small) reproducible test then I can look at it also.
>> You can send it to me directly by email (mtaal_at_elver.org).
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> So, in your estimation, there is no way EMF could be accessing those
>>> references and not triggering lazy loading? I suspect that the
>>> references are being retrieved using feature IDs, although I don't know
>>> that would make a difference.
>>>
>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>> literally creating the object, persisting it, reloading it and
>>> attempting to serialize to a resource. There is no adding to or removal
>>> from any list references going on. If this were the case, then I
>>> shouldn't be seeing an inconsistency between the in-memory and persisted
>>> representations, right?
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>> loading, even without going through the getter the lazy loaded list
>>>> should be automatically loaded when accessed (for example through an
>>>> iterator) and not have null values. Afaics null values in the list
>>>> point to the problem I described in my previous reply (holes in the
>>>> list).
>>>>
>>>> Regarding eager loading, there is this option:
>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>> then it will eagerly load all containment lists.
>>>>
>>>> gr. Martin
>>>>
>>>> Daniel Tuohy wrote:
>>>>> OK. I think I may have finally uncovered the real problem
>>>>>
>>>>> You're right about the association table. I had forgotten that I had
>>>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>>>> induces an association table. I did the same for the
>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>> problem for the object with the null references. The annotation is:
>>>>>
>>>>> <eclass name="WarfareSystem">
>>>>> <property name="dependencies">
>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>> <cascade>MERGE</cascade>
>>>>> <cascade>PERSIST</cascade>
>>>>> </many-to-many>
>>>>> </property>
>>>>> </eclass>
>>>>>
>>>>> So it's the lazy loading that's the problem. Because the references
>>>>> aren't actually null, they're just waiting for me to call
>>>>> system.getDependencies() to be loaded from the DB.
>>>>>
>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>> from the DB to a resource, and the EMF code doesn't do the nice thing
>>>>> and call system.getDependencies(), it just tries to persist what's
>>>>> already in memory. So I get the following error:
>>>>>
>>>>> java.lang.NullPointerException
>>>>> at
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>> at
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>> at
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>
>>>>> So there are two solutions:
>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>> to retrieve referenced objects.
>>>>> 2. I eagerly load everything (which is essentially every reference in
>>>>> my data model).
>>>>>
>>>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate
>>>>> to eagerly load *everything*?
>>>>>
>>>>>
>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>> Hi Daniel,
>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>> hibernate/sql error). Afaics the association you are mentioning below
>>>>>> is not persisted using a join table but using a foreign key in the
>>>>>> child table.
>>>>>> A cause for having null values in a list is that a child got deleted
>>>>>> without removing it from the list of the parent. For example if you
>>>>>> just read the child from the db (and not the parent) and then remove
>>>>>> the child then hibernate won't update the indexes in the list. This
>>>>>> results in a hole in the indexes in the childs. When reading the
>>>>>> contents of the list hibernate will place null values in the list in
>>>>>> the missing locations. You can check this out by looking in the db
>>>>>> and see if values in the warfaresystem_dependencies_idx column are
>>>>>> correct (no missing values).
>>>>>>
>>>>>> If this is the cause then there are two solutions:
>>>>>> - change your code so that when removing the child it is also removed
>>>>>> from the parent
>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>> column is not present. This is only possible if the order of the
>>>>>> children is not important. See here for more info:
>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> Daniel Tuohy wrote:
>>>>>>> Hi Guys,
>>>>>>>
>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>> were null when I reloaded them from the DB. I looked at the DB and
>>>>>>> found that I was inexplicably missing one of the association tables.
>>>>>>> The offending association is for the EMF-modeled type and reference
>>>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>>>> auto-genned hbm file is:
>>>>>>>
>>>>>>> <list name="dependencies" lazy="true">
>>>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>> not-null="false" unique="false"/>
>>>>>>> </key>
>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>> </list>
>>>>>>>
>>>>>>> The relevant mapping info message that is printed to console during
>>>>>>> the mapping is:
>>>>>>>
>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>>>
>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>> being persisted correctly with it's own association table. The
>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>> reference), and the info message is:
>>>>>>>
>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>> Step.outputsTo -> step_outputsto
>>>>>>>
>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>> perform to get you more info?
>>>>>>>
>>>>>>> Daniel
>>>>>> --
>>>>>>
>>>>>> With Regards, Martin Taal
>>>>>>
>>>>>> Springsite/Elver.org
>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>> The Netherlands
>>>>>> 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
>>>>>
>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>>
>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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: [Teneo] Association table not created for one-to-many EMF reference [message #115407 is a reply to message #115380] Sun, 23 March 2008 08:54 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hmmm, looking back to your remark in the beginning, what is also possible is that the one-to-many is
really a many-to-many.
So what can happen is that the elements in one list are present in another list also. When the lists
are mapped using foreign keys then when lists are persisted a list which is persisted later will
overwrite the foreign keys of the elements of a first list. So depending on the order in which lists
are persisted, it results in empty entries. A simple setting to try this out can be to set the
following option to true:
PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS

then you should get jointables for all associations (except contained).

or you can force a jointable for individual associations with the jointable annotation:
@JoinTable(name="MyGreatJoinTable")

or use the many-to-many as you mention below.

gr. Martin

Daniel Tuohy wrote:
> Sorry, I sent that prematurely. It was meant to end: "Does anything further
> occur to you in light of the answers to your questions, or due to the
> inconsistency in the contents of that list?"
>
> I should also note that I see this inconsistency only when I recreate the DB
> and persist the object each time I run the test. If I just load the object
> from the same DB repeatedly, the behavior is consistent.
>
> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
> news:fs3q7l$j5r$1@build.eclipse.org...
>> 1. Yes, it fails on the first element in the list.
>> 2. Yes. There are four elements in the list, and the last one is set,
>> the first three are null.
>> 3. The list is a HibernatePersistableEList.
>> 4. isLoaded() returns "true"
>>
>> I should also note that I am now seeing inconsistent behavior. Sometimes
>> the list for the object is full of the correct references, sometimes the
>> first three are null and only the last is set, and sometimes the list is
>> actually empty.
>>
>> The object being persisted is very elaborate, and the object whose
>> references are corrupted is contained within the object I'm trying to
>> serialize. The JUnit test I am running is not complicated, it consists of
>> object creation, persistence, retrieval, and serialization (failing on
>> serialization when it gets to these references).
>>
>> Unfortunately, it concerns a great deal of data and a large EMF model, so
>> I will have to consult my employer before I can commit to sending over a
>> test case. Does anything further oc
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:fs2lrj$nbg$1@build.eclipse.org...
>>> I agree that if you only do create, persist and reload that there should
>>> not be a hole-in-list
>>> situation.
>>> A few questions:
>>> - Does it fail on the first element in the list?
>>> - Are other parts of the list set?
>>> - What class is the list?
>>> - If it is one of the hibernate teneo list implementations, what does the
>>> isLoaded property say (just before the npe happens)?
>>>
>>> If you can make a (small) reproducible test then I can look at it also.
>>> You can send it to me directly by email (mtaal_at_elver.org).
>>>
>>> gr. Martin
>>>
>>> Daniel Tuohy wrote:
>>>> So, in your estimation, there is no way EMF could be accessing those
>>>> references and not triggering lazy loading? I suspect that the
>>>> references are being retrieved using feature IDs, although I don't know
>>>> that would make a difference.
>>>>
>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>> literally creating the object, persisting it, reloading it and
>>>> attempting to serialize to a resource. There is no adding to or removal
>>>> from any list references going on. If this were the case, then I
>>>> shouldn't be seeing an inconsistency between the in-memory and persisted
>>>> representations, right?
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>> loading, even without going through the getter the lazy loaded list
>>>>> should be automatically loaded when accessed (for example through an
>>>>> iterator) and not have null values. Afaics null values in the list
>>>>> point to the problem I described in my previous reply (holes in the
>>>>> list).
>>>>>
>>>>> Regarding eager loading, there is this option:
>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>>> then it will eagerly load all containment lists.
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>
>>>>>> You're right about the association table. I had forgotten that I had
>>>>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>>>>> induces an association table. I did the same for the
>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>> problem for the object with the null references. The annotation is:
>>>>>>
>>>>>> <eclass name="WarfareSystem">
>>>>>> <property name="dependencies">
>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>> <cascade>MERGE</cascade>
>>>>>> <cascade>PERSIST</cascade>
>>>>>> </many-to-many>
>>>>>> </property>
>>>>>> </eclass>
>>>>>>
>>>>>> So it's the lazy loading that's the problem. Because the references
>>>>>> aren't actually null, they're just waiting for me to call
>>>>>> system.getDependencies() to be loaded from the DB.
>>>>>>
>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>> from the DB to a resource, and the EMF code doesn't do the nice thing
>>>>>> and call system.getDependencies(), it just tries to persist what's
>>>>>> already in memory. So I get the following error:
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> at
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>> at
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>> at
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>
>>>>>> So there are two solutions:
>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>>> to retrieve referenced objects.
>>>>>> 2. I eagerly load everything (which is essentially every reference in
>>>>>> my data model).
>>>>>>
>>>>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate
>>>>>> to eagerly load *everything*?
>>>>>>
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>> Hi Daniel,
>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>> hibernate/sql error). Afaics the association you are mentioning below
>>>>>>> is not persisted using a join table but using a foreign key in the
>>>>>>> child table.
>>>>>>> A cause for having null values in a list is that a child got deleted
>>>>>>> without removing it from the list of the parent. For example if you
>>>>>>> just read the child from the db (and not the parent) and then remove
>>>>>>> the child then hibernate won't update the indexes in the list. This
>>>>>>> results in a hole in the indexes in the childs. When reading the
>>>>>>> contents of the list hibernate will place null values in the list in
>>>>>>> the missing locations. You can check this out by looking in the db
>>>>>>> and see if values in the warfaresystem_dependencies_idx column are
>>>>>>> correct (no missing values).
>>>>>>>
>>>>>>> If this is the cause then there are two solutions:
>>>>>>> - change your code so that when removing the child it is also removed
>>>>>>> from the parent
>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>> column is not present. This is only possible if the order of the
>>>>>>> children is not important. See here for more info:
>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Daniel Tuohy wrote:
>>>>>>>> Hi Guys,
>>>>>>>>
>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>> were null when I reloaded them from the DB. I looked at the DB and
>>>>>>>> found that I was inexplicably missing one of the association tables.
>>>>>>>> The offending association is for the EMF-modeled type and reference
>>>>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>>>>> auto-genned hbm file is:
>>>>>>>>
>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>> not-null="false" unique="false"/>
>>>>>>>> </key>
>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>> </list>
>>>>>>>>
>>>>>>>> The relevant mapping info message that is printed to console during
>>>>>>>> the mapping is:
>>>>>>>>
>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>>>>
>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>> reference), and the info message is:
>>>>>>>>
>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>>> Step.outputsTo -> step_outputsto
>>>>>>>>
>>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>>> perform to get you more info?
>>>>>>>>
>>>>>>>> Daniel
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #115436 is a reply to message #115407] Sun, 23 March 2008 14:59 Go to previous messageGo to next message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
I think you're right. It hadn't occured to me that this association was
n-to-m, but indeed it is. Without using that PersistenceOption, I'm still
seeing the error on some other objects, but I would bet that I've simply
overlooked another many-to-many association in the model.

"Martin Taal" <mtaal@elver.org> wrote in message
news:fs55t8$mqh$1@build.eclipse.org...
> Hmmm, looking back to your remark in the beginning, what is also possible
> is that the one-to-many is really a many-to-many.
> So what can happen is that the elements in one list are present in another
> list also. When the lists are mapped using foreign keys then when lists
> are persisted a list which is persisted later will overwrite the foreign
> keys of the elements of a first list. So depending on the order in which
> lists are persisted, it results in empty entries. A simple setting to try
> this out can be to set the following option to true:
> PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
>
> then you should get jointables for all associations (except contained).
>
> or you can force a jointable for individual associations with the
> jointable annotation:
> @JoinTable(name="MyGreatJoinTable")
>
> or use the many-to-many as you mention below.
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> Sorry, I sent that prematurely. It was meant to end: "Does anything
>> further occur to you in light of the answers to your questions, or due to
>> the inconsistency in the contents of that list?"
>>
>> I should also note that I see this inconsistency only when I recreate the
>> DB and persist the object each time I run the test. If I just load the
>> object from the same DB repeatedly, the behavior is consistent.
>>
>> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
>> news:fs3q7l$j5r$1@build.eclipse.org...
>>> 1. Yes, it fails on the first element in the list.
>>> 2. Yes. There are four elements in the list, and the last one is set,
>>> the first three are null.
>>> 3. The list is a HibernatePersistableEList.
>>> 4. isLoaded() returns "true"
>>>
>>> I should also note that I am now seeing inconsistent behavior.
>>> Sometimes the list for the object is full of the correct references,
>>> sometimes the first three are null and only the last is set, and
>>> sometimes the list is actually empty.
>>>
>>> The object being persisted is very elaborate, and the object whose
>>> references are corrupted is contained within the object I'm trying to
>>> serialize. The JUnit test I am running is not complicated, it consists
>>> of object creation, persistence, retrieval, and serialization (failing
>>> on serialization when it gets to these references).
>>>
>>> Unfortunately, it concerns a great deal of data and a large EMF model,
>>> so I will have to consult my employer before I can commit to sending
>>> over a test case. Does anything further oc
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:fs2lrj$nbg$1@build.eclipse.org...
>>>> I agree that if you only do create, persist and reload that there
>>>> should not be a hole-in-list
>>>> situation.
>>>> A few questions:
>>>> - Does it fail on the first element in the list?
>>>> - Are other parts of the list set?
>>>> - What class is the list?
>>>> - If it is one of the hibernate teneo list implementations, what does
>>>> the isLoaded property say (just before the npe happens)?
>>>>
>>>> If you can make a (small) reproducible test then I can look at it also.
>>>> You can send it to me directly by email (mtaal_at_elver.org).
>>>>
>>>> gr. Martin
>>>>
>>>> Daniel Tuohy wrote:
>>>>> So, in your estimation, there is no way EMF could be accessing those
>>>>> references and not triggering lazy loading? I suspect that the
>>>>> references are being retrieved using feature IDs, although I don't
>>>>> know that would make a difference.
>>>>>
>>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>>> literally creating the object, persisting it, reloading it and
>>>>> attempting to serialize to a resource. There is no adding to or
>>>>> removal from any list references going on. If this were the case,
>>>>> then I shouldn't be seeing an inconsistency between the in-memory and
>>>>> persisted representations, right?
>>>>>
>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>>> loading, even without going through the getter the lazy loaded list
>>>>>> should be automatically loaded when accessed (for example through an
>>>>>> iterator) and not have null values. Afaics null values in the list
>>>>>> point to the problem I described in my previous reply (holes in the
>>>>>> list).
>>>>>>
>>>>>> Regarding eager loading, there is this option:
>>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>>>> then it will eagerly load all containment lists.
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> Daniel Tuohy wrote:
>>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>>
>>>>>>> You're right about the association table. I had forgotten that I
>>>>>>> had added an annotation for "Step.outputsTo" that (for whatever
>>>>>>> reason) induces an association table. I did the same for the
>>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>>> problem for the object with the null references. The annotation is:
>>>>>>>
>>>>>>> <eclass name="WarfareSystem">
>>>>>>> <property name="dependencies">
>>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>>> <cascade>MERGE</cascade>
>>>>>>> <cascade>PERSIST</cascade>
>>>>>>> </many-to-many>
>>>>>>> </property>
>>>>>>> </eclass>
>>>>>>>
>>>>>>> So it's the lazy loading that's the problem. Because the references
>>>>>>> aren't actually null, they're just waiting for me to call
>>>>>>> system.getDependencies() to be loaded from the DB.
>>>>>>>
>>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>>> from the DB to a resource, and the EMF code doesn't do the nice
>>>>>>> thing and call system.getDependencies(), it just tries to persist
>>>>>>> what's already in memory. So I get the following error:
>>>>>>>
>>>>>>> java.lang.NullPointerException
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>>
>>>>>>> So there are two solutions:
>>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>>>> to retrieve referenced objects.
>>>>>>> 2. I eagerly load everything (which is essentially every reference
>>>>>>> in my data model).
>>>>>>>
>>>>>>> If (2) is my only option, is there an easy way to tell
>>>>>>> Teneo/Hibernate to eagerly load *everything*?
>>>>>>>
>>>>>>>
>>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>>> Hi Daniel,
>>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>>> hibernate/sql error). Afaics the association you are mentioning
>>>>>>>> below is not persisted using a join table but using a foreign key
>>>>>>>> in the child table.
>>>>>>>> A cause for having null values in a list is that a child got
>>>>>>>> deleted without removing it from the list of the parent. For
>>>>>>>> example if you just read the child from the db (and not the parent)
>>>>>>>> and then remove the child then hibernate won't update the indexes
>>>>>>>> in the list. This results in a hole in the indexes in the childs.
>>>>>>>> When reading the contents of the list hibernate will place null
>>>>>>>> values in the list in the missing locations. You can check this out
>>>>>>>> by looking in the db and see if values in the
>>>>>>>> warfaresystem_dependencies_idx column are correct (no missing
>>>>>>>> values).
>>>>>>>>
>>>>>>>> If this is the cause then there are two solutions:
>>>>>>>> - change your code so that when removing the child it is also
>>>>>>>> removed from the parent
>>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>>> column is not present. This is only possible if the order of the
>>>>>>>> children is not important. See here for more info:
>>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> Daniel Tuohy wrote:
>>>>>>>>> Hi Guys,
>>>>>>>>>
>>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>>> were null when I reloaded them from the DB. I looked at the DB
>>>>>>>>> and found that I was inexplicably missing one of the association
>>>>>>>>> tables. The offending association is for the EMF-modeled type and
>>>>>>>>> reference "WarfareSystem.dependencies". The corresponding entry
>>>>>>>>> in the auto-genned hbm file is:
>>>>>>>>>
>>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>>> <key update="true"
>>>>>>>>> foreign-key="warfaresystem_dependencies">
>>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>> </key>
>>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>>> </list>
>>>>>>>>>
>>>>>>>>> The relevant mapping info message that is printed to console
>>>>>>>>> during the mapping is:
>>>>>>>>>
>>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>> collection: WarfareSystem.dependencies -> warfaresystem
>>>>>>>>>
>>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>>> reference), and the info message is:
>>>>>>>>>
>>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>> collection: Step.outputsTo -> step_outputsto
>>>>>>>>>
>>>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>>>> perform to get you more info?
>>>>>>>>>
>>>>>>>>> Daniel
>>>>>>>> --
>>>>>>>>
>>>>>>>> With Regards, Martin Taal
>>>>>>>>
>>>>>>>> Springsite/Elver.org
>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>> The Netherlands
>>>>>>>> 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
>>>>>> --
>>>>>>
>>>>>> With Regards, Martin Taal
>>>>>>
>>>>>> Springsite/Elver.org
>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>> The Netherlands
>>>>>> 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
>>>>>
>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #115449 is a reply to message #115436] Sun, 23 March 2008 15:01 Go to previous messageGo to next message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
And thanks so much for your help!

"Daniel Tuohy" <danielr2e@gmail.com> wrote in message
news:fs5r4g$s8q$1@build.eclipse.org...
>I think you're right. It hadn't occured to me that this association was
>n-to-m, but indeed it is. Without using that PersistenceOption, I'm still
>seeing the error on some other objects, but I would bet that I've simply
>overlooked another many-to-many association in the model.
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fs55t8$mqh$1@build.eclipse.org...
>> Hmmm, looking back to your remark in the beginning, what is also possible
>> is that the one-to-many is really a many-to-many.
>> So what can happen is that the elements in one list are present in
>> another list also. When the lists are mapped using foreign keys then when
>> lists are persisted a list which is persisted later will overwrite the
>> foreign keys of the elements of a first list. So depending on the order
>> in which lists are persisted, it results in empty entries. A simple
>> setting to try this out can be to set the following option to true:
>> PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
>>
>> then you should get jointables for all associations (except contained).
>>
>> or you can force a jointable for individual associations with the
>> jointable annotation:
>> @JoinTable(name="MyGreatJoinTable")
>>
>> or use the many-to-many as you mention below.
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> Sorry, I sent that prematurely. It was meant to end: "Does anything
>>> further occur to you in light of the answers to your questions, or due
>>> to the inconsistency in the contents of that list?"
>>>
>>> I should also note that I see this inconsistency only when I recreate
>>> the DB and persist the object each time I run the test. If I just load
>>> the object from the same DB repeatedly, the behavior is consistent.
>>>
>>> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
>>> news:fs3q7l$j5r$1@build.eclipse.org...
>>>> 1. Yes, it fails on the first element in the list.
>>>> 2. Yes. There are four elements in the list, and the last one is set,
>>>> the first three are null.
>>>> 3. The list is a HibernatePersistableEList.
>>>> 4. isLoaded() returns "true"
>>>>
>>>> I should also note that I am now seeing inconsistent behavior.
>>>> Sometimes the list for the object is full of the correct references,
>>>> sometimes the first three are null and only the last is set, and
>>>> sometimes the list is actually empty.
>>>>
>>>> The object being persisted is very elaborate, and the object whose
>>>> references are corrupted is contained within the object I'm trying to
>>>> serialize. The JUnit test I am running is not complicated, it consists
>>>> of object creation, persistence, retrieval, and serialization (failing
>>>> on serialization when it gets to these references).
>>>>
>>>> Unfortunately, it concerns a great deal of data and a large EMF model,
>>>> so I will have to consult my employer before I can commit to sending
>>>> over a test case. Does anything further oc
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:fs2lrj$nbg$1@build.eclipse.org...
>>>>> I agree that if you only do create, persist and reload that there
>>>>> should not be a hole-in-list
>>>>> situation.
>>>>> A few questions:
>>>>> - Does it fail on the first element in the list?
>>>>> - Are other parts of the list set?
>>>>> - What class is the list?
>>>>> - If it is one of the hibernate teneo list implementations, what does
>>>>> the isLoaded property say (just before the npe happens)?
>>>>>
>>>>> If you can make a (small) reproducible test then I can look at it
>>>>> also. You can send it to me directly by email (mtaal_at_elver.org).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> So, in your estimation, there is no way EMF could be accessing those
>>>>>> references and not triggering lazy loading? I suspect that the
>>>>>> references are being retrieved using feature IDs, although I don't
>>>>>> know that would make a difference.
>>>>>>
>>>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>>>> literally creating the object, persisting it, reloading it and
>>>>>> attempting to serialize to a resource. There is no adding to or
>>>>>> removal from any list references going on. If this were the case,
>>>>>> then I shouldn't be seeing an inconsistency between the in-memory and
>>>>>> persisted representations, right?
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>>>> loading, even without going through the getter the lazy loaded list
>>>>>>> should be automatically loaded when accessed (for example through an
>>>>>>> iterator) and not have null values. Afaics null values in the list
>>>>>>> point to the problem I described in my previous reply (holes in the
>>>>>>> list).
>>>>>>>
>>>>>>> Regarding eager loading, there is this option:
>>>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to
>>>>>>> true then it will eagerly load all containment lists.
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Daniel Tuohy wrote:
>>>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>>>
>>>>>>>> You're right about the association table. I had forgotten that I
>>>>>>>> had added an annotation for "Step.outputsTo" that (for whatever
>>>>>>>> reason) induces an association table. I did the same for the
>>>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>>>> problem for the object with the null references. The annotation
>>>>>>>> is:
>>>>>>>>
>>>>>>>> <eclass name="WarfareSystem">
>>>>>>>> <property name="dependencies">
>>>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>>>> <cascade>MERGE</cascade>
>>>>>>>> <cascade>PERSIST</cascade>
>>>>>>>> </many-to-many>
>>>>>>>> </property>
>>>>>>>> </eclass>
>>>>>>>>
>>>>>>>> So it's the lazy loading that's the problem. Because the
>>>>>>>> references aren't actually null, they're just waiting for me to
>>>>>>>> call system.getDependencies() to be loaded from the DB.
>>>>>>>>
>>>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>>>> from the DB to a resource, and the EMF code doesn't do the nice
>>>>>>>> thing and call system.getDependencies(), it just tries to persist
>>>>>>>> what's already in memory. So I get the following error:
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>>>
>>>>>>>> So there are two solutions:
>>>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>>>> serialization code call the appropriate methods to trigger
>>>>>>>> hibernate to retrieve referenced objects.
>>>>>>>> 2. I eagerly load everything (which is essentially every reference
>>>>>>>> in my data model).
>>>>>>>>
>>>>>>>> If (2) is my only option, is there an easy way to tell
>>>>>>>> Teneo/Hibernate to eagerly load *everything*?
>>>>>>>>
>>>>>>>>
>>>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>>>> Hi Daniel,
>>>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>>>> hibernate/sql error). Afaics the association you are mentioning
>>>>>>>>> below is not persisted using a join table but using a foreign key
>>>>>>>>> in the child table.
>>>>>>>>> A cause for having null values in a list is that a child got
>>>>>>>>> deleted without removing it from the list of the parent. For
>>>>>>>>> example if you just read the child from the db (and not the
>>>>>>>>> parent) and then remove the child then hibernate won't update the
>>>>>>>>> indexes in the list. This results in a hole in the indexes in the
>>>>>>>>> childs. When reading the contents of the list hibernate will place
>>>>>>>>> null values in the list in the missing locations. You can check
>>>>>>>>> this out by looking in the db and see if values in the
>>>>>>>>> warfaresystem_dependencies_idx column are correct (no missing
>>>>>>>>> values).
>>>>>>>>>
>>>>>>>>> If this is the cause then there are two solutions:
>>>>>>>>> - change your code so that when removing the child it is also
>>>>>>>>> removed from the parent
>>>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>>>> column is not present. This is only possible if the order of the
>>>>>>>>> children is not important. See here for more info:
>>>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> Daniel Tuohy wrote:
>>>>>>>>>> Hi Guys,
>>>>>>>>>>
>>>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>>>> were null when I reloaded them from the DB. I looked at the DB
>>>>>>>>>> and found that I was inexplicably missing one of the association
>>>>>>>>>> tables. The offending association is for the EMF-modeled type and
>>>>>>>>>> reference "WarfareSystem.dependencies". The corresponding entry
>>>>>>>>>> in the auto-genned hbm file is:
>>>>>>>>>>
>>>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>>>> <key update="true"
>>>>>>>>>> foreign-key="warfaresystem_dependencies">
>>>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>>>> </list>
>>>>>>>>>>
>>>>>>>>>> The relevant mapping info message that is printed to console
>>>>>>>>>> during the mapping is:
>>>>>>>>>>
>>>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: WarfareSystem.dependencies -> warfaresystem
>>>>>>>>>>
>>>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>>>> reference), and the info message is:
>>>>>>>>>>
>>>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: Step.outputsTo -> step_outputsto
>>>>>>>>>>
>>>>>>>>>> Which I believe is correct. Any idea why this might happen to
>>>>>>>>>> the "dependencies" reference? Are there any other diagnostics I
>>>>>>>>>> can perform to get you more info?
>>>>>>>>>>
>>>>>>>>>> Daniel
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> With Regards, Martin Taal
>>>>>>>>>
>>>>>>>>> Springsite/Elver.org
>>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>>> The Netherlands
>>>>>>>>> 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
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>>
>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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: [Teneo] Association table not created for one-to-many EMF reference [message #115527 is a reply to message #115436] Sun, 23 March 2008 20:19 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
It is good that I now know of this issue. I am considering of changing the option below to a default
value of true (so always have jointables). It seems to be a safer first approach. This will probably
be in the next release.

gr. Martin

Daniel Tuohy wrote:
> I think you're right. It hadn't occured to me that this association was
> n-to-m, but indeed it is. Without using that PersistenceOption, I'm still
> seeing the error on some other objects, but I would bet that I've simply
> overlooked another many-to-many association in the model.
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fs55t8$mqh$1@build.eclipse.org...
>> Hmmm, looking back to your remark in the beginning, what is also possible
>> is that the one-to-many is really a many-to-many.
>> So what can happen is that the elements in one list are present in another
>> list also. When the lists are mapped using foreign keys then when lists
>> are persisted a list which is persisted later will overwrite the foreign
>> keys of the elements of a first list. So depending on the order in which
>> lists are persisted, it results in empty entries. A simple setting to try
>> this out can be to set the following option to true:
>> PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
>>
>> then you should get jointables for all associations (except contained).
>>
>> or you can force a jointable for individual associations with the
>> jointable annotation:
>> @JoinTable(name="MyGreatJoinTable")
>>
>> or use the many-to-many as you mention below.
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> Sorry, I sent that prematurely. It was meant to end: "Does anything
>>> further occur to you in light of the answers to your questions, or due to
>>> the inconsistency in the contents of that list?"
>>>
>>> I should also note that I see this inconsistency only when I recreate the
>>> DB and persist the object each time I run the test. If I just load the
>>> object from the same DB repeatedly, the behavior is consistent.
>>>
>>> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
>>> news:fs3q7l$j5r$1@build.eclipse.org...
>>>> 1. Yes, it fails on the first element in the list.
>>>> 2. Yes. There are four elements in the list, and the last one is set,
>>>> the first three are null.
>>>> 3. The list is a HibernatePersistableEList.
>>>> 4. isLoaded() returns "true"
>>>>
>>>> I should also note that I am now seeing inconsistent behavior.
>>>> Sometimes the list for the object is full of the correct references,
>>>> sometimes the first three are null and only the last is set, and
>>>> sometimes the list is actually empty.
>>>>
>>>> The object being persisted is very elaborate, and the object whose
>>>> references are corrupted is contained within the object I'm trying to
>>>> serialize. The JUnit test I am running is not complicated, it consists
>>>> of object creation, persistence, retrieval, and serialization (failing
>>>> on serialization when it gets to these references).
>>>>
>>>> Unfortunately, it concerns a great deal of data and a large EMF model,
>>>> so I will have to consult my employer before I can commit to sending
>>>> over a test case. Does anything further oc
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:fs2lrj$nbg$1@build.eclipse.org...
>>>>> I agree that if you only do create, persist and reload that there
>>>>> should not be a hole-in-list
>>>>> situation.
>>>>> A few questions:
>>>>> - Does it fail on the first element in the list?
>>>>> - Are other parts of the list set?
>>>>> - What class is the list?
>>>>> - If it is one of the hibernate teneo list implementations, what does
>>>>> the isLoaded property say (just before the npe happens)?
>>>>>
>>>>> If you can make a (small) reproducible test then I can look at it also.
>>>>> You can send it to me directly by email (mtaal_at_elver.org).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> So, in your estimation, there is no way EMF could be accessing those
>>>>>> references and not triggering lazy loading? I suspect that the
>>>>>> references are being retrieved using feature IDs, although I don't
>>>>>> know that would make a difference.
>>>>>>
>>>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>>>> literally creating the object, persisting it, reloading it and
>>>>>> attempting to serialize to a resource. There is no adding to or
>>>>>> removal from any list references going on. If this were the case,
>>>>>> then I shouldn't be seeing an inconsistency between the in-memory and
>>>>>> persisted representations, right?
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>>>> loading, even without going through the getter the lazy loaded list
>>>>>>> should be automatically loaded when accessed (for example through an
>>>>>>> iterator) and not have null values. Afaics null values in the list
>>>>>>> point to the problem I described in my previous reply (holes in the
>>>>>>> list).
>>>>>>>
>>>>>>> Regarding eager loading, there is this option:
>>>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>>>>> then it will eagerly load all containment lists.
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Daniel Tuohy wrote:
>>>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>>>
>>>>>>>> You're right about the association table. I had forgotten that I
>>>>>>>> had added an annotation for "Step.outputsTo" that (for whatever
>>>>>>>> reason) induces an association table. I did the same for the
>>>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>>>> problem for the object with the null references. The annotation is:
>>>>>>>>
>>>>>>>> <eclass name="WarfareSystem">
>>>>>>>> <property name="dependencies">
>>>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>>>> <cascade>MERGE</cascade>
>>>>>>>> <cascade>PERSIST</cascade>
>>>>>>>> </many-to-many>
>>>>>>>> </property>
>>>>>>>> </eclass>
>>>>>>>>
>>>>>>>> So it's the lazy loading that's the problem. Because the references
>>>>>>>> aren't actually null, they're just waiting for me to call
>>>>>>>> system.getDependencies() to be loaded from the DB.
>>>>>>>>
>>>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>>>> from the DB to a resource, and the EMF code doesn't do the nice
>>>>>>>> thing and call system.getDependencies(), it just tries to persist
>>>>>>>> what's already in memory. So I get the following error:
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>>>
>>>>>>>> So there are two solutions:
>>>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>>>>> to retrieve referenced objects.
>>>>>>>> 2. I eagerly load everything (which is essentially every reference
>>>>>>>> in my data model).
>>>>>>>>
>>>>>>>> If (2) is my only option, is there an easy way to tell
>>>>>>>> Teneo/Hibernate to eagerly load *everything*?
>>>>>>>>
>>>>>>>>
>>>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>>>> Hi Daniel,
>>>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>>>> hibernate/sql error). Afaics the association you are mentioning
>>>>>>>>> below is not persisted using a join table but using a foreign key
>>>>>>>>> in the child table.
>>>>>>>>> A cause for having null values in a list is that a child got
>>>>>>>>> deleted without removing it from the list of the parent. For
>>>>>>>>> example if you just read the child from the db (and not the parent)
>>>>>>>>> and then remove the child then hibernate won't update the indexes
>>>>>>>>> in the list. This results in a hole in the indexes in the childs.
>>>>>>>>> When reading the contents of the list hibernate will place null
>>>>>>>>> values in the list in the missing locations. You can check this out
>>>>>>>>> by looking in the db and see if values in the
>>>>>>>>> warfaresystem_dependencies_idx column are correct (no missing
>>>>>>>>> values).
>>>>>>>>>
>>>>>>>>> If this is the cause then there are two solutions:
>>>>>>>>> - change your code so that when removing the child it is also
>>>>>>>>> removed from the parent
>>>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>>>> column is not present. This is only possible if the order of the
>>>>>>>>> children is not important. See here for more info:
>>>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> Daniel Tuohy wrote:
>>>>>>>>>> Hi Guys,
>>>>>>>>>>
>>>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>>>> were null when I reloaded them from the DB. I looked at the DB
>>>>>>>>>> and found that I was inexplicably missing one of the association
>>>>>>>>>> tables. The offending association is for the EMF-modeled type and
>>>>>>>>>> reference "WarfareSystem.dependencies". The corresponding entry
>>>>>>>>>> in the auto-genned hbm file is:
>>>>>>>>>>
>>>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>>>> <key update="true"
>>>>>>>>>> foreign-key="warfaresystem_dependencies">
>>>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>>>> </list>
>>>>>>>>>>
>>>>>>>>>> The relevant mapping info message that is printed to console
>>>>>>>>>> during the mapping is:
>>>>>>>>>>
>>>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: WarfareSystem.dependencies -> warfaresystem
>>>>>>>>>>
>>>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>>>> reference), and the info message is:
>>>>>>>>>>
>>>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: Step.outputsTo -> step_outputsto
>>>>>>>>>>
>>>>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>>>>> perform to get you more info?
>>>>>>>>>>
>>>>>>>>>> Daniel
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> With Regards, Martin Taal
>>>>>>>>>
>>>>>>>>> Springsite/Elver.org
>>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>>> The Netherlands
>>>>>>>>> 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
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #615941 is a reply to message #115219] Thu, 20 March 2008 22:49 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Daniel,
I think it is not a missing table (otherwise you would get a hibernate/sql error). Afaics the
association you are mentioning below is not persisted using a join table but using a foreign key in
the child table.
A cause for having null values in a list is that a child got deleted without removing it from the
list of the parent. For example if you just read the child from the db (and not the parent) and then
remove the child then hibernate won't update the indexes in the list. This results in a hole in the
indexes in the childs. When reading the contents of the list hibernate will place null values in the
list in the missing locations. You can check this out by looking in the db and see if values in the
warfaresystem_dependencies_idx column are correct (no missing values).

If this is the cause then there are two solutions:
- change your code so that when removing the child it is also removed from the parent
- change the mapping to a set/bag instead of a list, then the idx column is not present. This is
only possible if the order of the children is not important. See here for more info:
http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations

gr. Martin

Daniel Tuohy wrote:
> Hi Guys,
>
> I noticed that some references in my data (persisted with Teneo) were null
> when I reloaded them from the DB. I looked at the DB and found that I was
> inexplicably missing one of the association tables. The offending
> association is for the EMF-modeled type and reference
> "WarfareSystem.dependencies". The corresponding entry in the auto-genned
> hbm file is:
>
> <list name="dependencies" lazy="true">
> <key update="true" foreign-key="warfaresystem_dependencies">
> <column name="`warfaresystem_dependencies_e_id`"
> not-null="false" unique="false"/>
> </key>
> <list-index column="`warfaresystem_dependencies_idx`"/>
> <one-to-many entity-name="WarfareSystem"/>
> </list>
>
> The relevant mapping info message that is printed to console during the
> mapping is:
>
> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
> WarfareSystem.dependencies -> warfaresystem
>
> Note that I have an analagous reference for another type that is being
> persisted correctly with it's own association table. The entry in the hbm
> file is identical (modulo the name/type of the reference), and the info
> message is:
>
> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
> Step.outputsTo -> step_outputsto
>
> Which I believe is correct. Any idea why this might happen to the
> "dependencies" reference? Are there any other diagnostics I can perform to
> get you more info?
>
> Daniel
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #615942 is a reply to message #115233] Fri, 21 March 2008 01:52 Go to previous message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
OK. I think I may have finally uncovered the real problem

You're right about the association table. I had forgotten that I had added
an annotation for "Step.outputsTo" that (for whatever reason) induces an
association table. I did the same for the "Warfare.dependencies" reference
and it appears to have solved the problem for the object with the null
references. The annotation is:

<eclass name="WarfareSystem">
<property name="dependencies">
<many-to-many fetch="EAGER" target-entity="WarfareSystem">
<cascade>MERGE</cascade>
<cascade>PERSIST</cascade>
</many-to-many>
</property>
</eclass>

So it's the lazy loading that's the problem. Because the references aren't
actually null, they're just waiting for me to call system.getDependencies()
to be loaded from the DB.

This poses a problem, however. I'm trying to serialize the object from the
DB to a resource, and the EMF code doesn't do the nice thing and call
system.getDependencies(), it just tries to persist what's already in memory.
So I get the following error:

java.lang.NullPointerException
at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)

So there are two solutions:
1. I find some way (or petition the EMF guys) to make the EMF serialization
code call the appropriate methods to trigger hibernate to retrieve
referenced objects.
2. I eagerly load everything (which is essentially every reference in my
data model).

If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
eagerly load *everything*?


"Martin Taal" <mtaal@elver.org> wrote in message
news:fruplj$p6$1@build.eclipse.org...
> Hi Daniel,
> I think it is not a missing table (otherwise you would get a hibernate/sql
> error). Afaics the association you are mentioning below is not persisted
> using a join table but using a foreign key in the child table.
> A cause for having null values in a list is that a child got deleted
> without removing it from the list of the parent. For example if you just
> read the child from the db (and not the parent) and then remove the child
> then hibernate won't update the indexes in the list. This results in a
> hole in the indexes in the childs. When reading the contents of the list
> hibernate will place null values in the list in the missing locations. You
> can check this out by looking in the db and see if values in the
> warfaresystem_dependencies_idx column are correct (no missing values).
>
> If this is the cause then there are two solutions:
> - change your code so that when removing the child it is also removed from
> the parent
> - change the mapping to a set/bag instead of a list, then the idx column
> is not present. This is only possible if the order of the children is not
> important. See here for more info:
> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> Hi Guys,
>>
>> I noticed that some references in my data (persisted with Teneo) were
>> null when I reloaded them from the DB. I looked at the DB and found that
>> I was inexplicably missing one of the association tables. The offending
>> association is for the EMF-modeled type and reference
>> "WarfareSystem.dependencies". The corresponding entry in the auto-genned
>> hbm file is:
>>
>> <list name="dependencies" lazy="true">
>> <key update="true" foreign-key="warfaresystem_dependencies">
>> <column name="`warfaresystem_dependencies_e_id`"
>> not-null="false" unique="false"/>
>> </key>
>> <list-index column="`warfaresystem_dependencies_idx`"/>
>> <one-to-many entity-name="WarfareSystem"/>
>> </list>
>>
>> The relevant mapping info message that is printed to console during the
>> mapping is:
>>
>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>> WarfareSystem.dependencies -> warfaresystem
>>
>> Note that I have an analagous reference for another type that is being
>> persisted correctly with it's own association table. The entry in the
>> hbm file is identical (modulo the name/type of the reference), and the
>> info message is:
>>
>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>> Step.outputsTo -> step_outputsto
>>
>> Which I believe is correct. Any idea why this might happen to the
>> "dependencies" reference? Are there any other diagnostics I can perform
>> to get you more info?
>>
>> Daniel
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #615944 is a reply to message #115247] Fri, 21 March 2008 05:43 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I am not sure why the many-to-many solved your npe. Regarding lazy loading, even without going
through the getter the lazy loaded list should be automatically loaded when accessed (for example
through an iterator) and not have null values. Afaics null values in the list point to the problem I
described in my previous reply (holes in the list).

Regarding eager loading, there is this option: PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you
set this to true then it will eagerly load all containment lists.

gr. Martin

Daniel Tuohy wrote:
> OK. I think I may have finally uncovered the real problem
>
> You're right about the association table. I had forgotten that I had added
> an annotation for "Step.outputsTo" that (for whatever reason) induces an
> association table. I did the same for the "Warfare.dependencies" reference
> and it appears to have solved the problem for the object with the null
> references. The annotation is:
>
> <eclass name="WarfareSystem">
> <property name="dependencies">
> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
> <cascade>MERGE</cascade>
> <cascade>PERSIST</cascade>
> </many-to-many>
> </property>
> </eclass>
>
> So it's the lazy loading that's the problem. Because the references aren't
> actually null, they're just waiting for me to call system.getDependencies()
> to be loaded from the DB.
>
> This poses a problem, however. I'm trying to serialize the object from the
> DB to a resource, and the EMF code doesn't do the nice thing and call
> system.getDependencies(), it just tries to persist what's already in memory.
> So I get the following error:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>
> So there are two solutions:
> 1. I find some way (or petition the EMF guys) to make the EMF serialization
> code call the appropriate methods to trigger hibernate to retrieve
> referenced objects.
> 2. I eagerly load everything (which is essentially every reference in my
> data model).
>
> If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
> eagerly load *everything*?
>
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fruplj$p6$1@build.eclipse.org...
>> Hi Daniel,
>> I think it is not a missing table (otherwise you would get a hibernate/sql
>> error). Afaics the association you are mentioning below is not persisted
>> using a join table but using a foreign key in the child table.
>> A cause for having null values in a list is that a child got deleted
>> without removing it from the list of the parent. For example if you just
>> read the child from the db (and not the parent) and then remove the child
>> then hibernate won't update the indexes in the list. This results in a
>> hole in the indexes in the childs. When reading the contents of the list
>> hibernate will place null values in the list in the missing locations. You
>> can check this out by looking in the db and see if values in the
>> warfaresystem_dependencies_idx column are correct (no missing values).
>>
>> If this is the cause then there are two solutions:
>> - change your code so that when removing the child it is also removed from
>> the parent
>> - change the mapping to a set/bag instead of a list, then the idx column
>> is not present. This is only possible if the order of the children is not
>> important. See here for more info:
>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> Hi Guys,
>>>
>>> I noticed that some references in my data (persisted with Teneo) were
>>> null when I reloaded them from the DB. I looked at the DB and found that
>>> I was inexplicably missing one of the association tables. The offending
>>> association is for the EMF-modeled type and reference
>>> "WarfareSystem.dependencies". The corresponding entry in the auto-genned
>>> hbm file is:
>>>
>>> <list name="dependencies" lazy="true">
>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>> <column name="`warfaresystem_dependencies_e_id`"
>>> not-null="false" unique="false"/>
>>> </key>
>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>> <one-to-many entity-name="WarfareSystem"/>
>>> </list>
>>>
>>> The relevant mapping info message that is printed to console during the
>>> mapping is:
>>>
>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>> WarfareSystem.dependencies -> warfaresystem
>>>
>>> Note that I have an analagous reference for another type that is being
>>> persisted correctly with it's own association table. The entry in the
>>> hbm file is identical (modulo the name/type of the reference), and the
>>> info message is:
>>>
>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>> Step.outputsTo -> step_outputsto
>>>
>>> Which I believe is correct. Any idea why this might happen to the
>>> "dependencies" reference? Are there any other diagnostics I can perform
>>> to get you more info?
>>>
>>> Daniel
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #615946 is a reply to message #115273] Fri, 21 March 2008 21:04 Go to previous message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
So, in your estimation, there is no way EMF could be accessing those
references and not triggering lazy loading? I suspect that the references
are being retrieved using feature IDs, although I don't know that would make
a difference.

As far as the holes-in-the-list conjecture, I should mention that I'm
literally creating the object, persisting it, reloading it and attempting to
serialize to a resource. There is no adding to or removal from any list
references going on. If this were the case, then I shouldn't be seeing an
inconsistency between the in-memory and persisted representations, right?

"Martin Taal" <mtaal@elver.org> wrote in message
news:frvhu0$ha9$1@build.eclipse.org...
>I am not sure why the many-to-many solved your npe. Regarding lazy loading,
>even without going through the getter the lazy loaded list should be
>automatically loaded when accessed (for example through an iterator) and
>not have null values. Afaics null values in the list point to the problem I
>described in my previous reply (holes in the list).
>
> Regarding eager loading, there is this option:
> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true then
> it will eagerly load all containment lists.
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> OK. I think I may have finally uncovered the real problem
>>
>> You're right about the association table. I had forgotten that I had
>> added an annotation for "Step.outputsTo" that (for whatever reason)
>> induces an association table. I did the same for the
>> "Warfare.dependencies" reference and it appears to have solved the
>> problem for the object with the null references. The annotation is:
>>
>> <eclass name="WarfareSystem">
>> <property name="dependencies">
>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>> <cascade>MERGE</cascade>
>> <cascade>PERSIST</cascade>
>> </many-to-many>
>> </property>
>> </eclass>
>>
>> So it's the lazy loading that's the problem. Because the references
>> aren't actually null, they're just waiting for me to call
>> system.getDependencies() to be loaded from the DB.
>>
>> This poses a problem, however. I'm trying to serialize the object from
>> the DB to a resource, and the EMF code doesn't do the nice thing and call
>> system.getDependencies(), it just tries to persist what's already in
>> memory. So I get the following error:
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>
>> So there are two solutions:
>> 1. I find some way (or petition the EMF guys) to make the EMF
>> serialization code call the appropriate methods to trigger hibernate to
>> retrieve referenced objects.
>> 2. I eagerly load everything (which is essentially every reference in my
>> data model).
>>
>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
>> eagerly load *everything*?
>>
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:fruplj$p6$1@build.eclipse.org...
>>> Hi Daniel,
>>> I think it is not a missing table (otherwise you would get a
>>> hibernate/sql error). Afaics the association you are mentioning below is
>>> not persisted using a join table but using a foreign key in the child
>>> table.
>>> A cause for having null values in a list is that a child got deleted
>>> without removing it from the list of the parent. For example if you just
>>> read the child from the db (and not the parent) and then remove the
>>> child then hibernate won't update the indexes in the list. This results
>>> in a hole in the indexes in the childs. When reading the contents of the
>>> list hibernate will place null values in the list in the missing
>>> locations. You can check this out by looking in the db and see if values
>>> in the warfaresystem_dependencies_idx column are correct (no missing
>>> values).
>>>
>>> If this is the cause then there are two solutions:
>>> - change your code so that when removing the child it is also removed
>>> from the parent
>>> - change the mapping to a set/bag instead of a list, then the idx column
>>> is not present. This is only possible if the order of the children is
>>> not important. See here for more info:
>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>
>>> gr. Martin
>>>
>>> Daniel Tuohy wrote:
>>>> Hi Guys,
>>>>
>>>> I noticed that some references in my data (persisted with Teneo) were
>>>> null when I reloaded them from the DB. I looked at the DB and found
>>>> that I was inexplicably missing one of the association tables. The
>>>> offending association is for the EMF-modeled type and reference
>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>> auto-genned hbm file is:
>>>>
>>>> <list name="dependencies" lazy="true">
>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>> not-null="false" unique="false"/>
>>>> </key>
>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>> <one-to-many entity-name="WarfareSystem"/>
>>>> </list>
>>>>
>>>> The relevant mapping info message that is printed to console during the
>>>> mapping is:
>>>>
>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>> WarfareSystem.dependencies -> warfaresystem
>>>>
>>>> Note that I have an analagous reference for another type that is being
>>>> persisted correctly with it's own association table. The entry in the
>>>> hbm file is identical (modulo the name/type of the reference), and the
>>>> info message is:
>>>>
>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>> Step.outputsTo -> step_outputsto
>>>>
>>>> Which I believe is correct. Any idea why this might happen to the
>>>> "dependencies" reference? Are there any other diagnostics I can
>>>> perform to get you more info?
>>>>
>>>> Daniel
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #615947 is a reply to message #115299] Sat, 22 March 2008 10:08 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I agree that if you only do create, persist and reload that there should not be a hole-in-list
situation.
A few questions:
- Does it fail on the first element in the list?
- Are other parts of the list set?
- What class is the list?
- If it is one of the hibernate teneo list implementations, what does the isLoaded property say
(just before the npe happens)?

If you can make a (small) reproducible test then I can look at it also. You can send it to me
directly by email (mtaal_at_elver.org).

gr. Martin

Daniel Tuohy wrote:
> So, in your estimation, there is no way EMF could be accessing those
> references and not triggering lazy loading? I suspect that the references
> are being retrieved using feature IDs, although I don't know that would make
> a difference.
>
> As far as the holes-in-the-list conjecture, I should mention that I'm
> literally creating the object, persisting it, reloading it and attempting to
> serialize to a resource. There is no adding to or removal from any list
> references going on. If this were the case, then I shouldn't be seeing an
> inconsistency between the in-memory and persisted representations, right?
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:frvhu0$ha9$1@build.eclipse.org...
>> I am not sure why the many-to-many solved your npe. Regarding lazy loading,
>> even without going through the getter the lazy loaded list should be
>> automatically loaded when accessed (for example through an iterator) and
>> not have null values. Afaics null values in the list point to the problem I
>> described in my previous reply (holes in the list).
>>
>> Regarding eager loading, there is this option:
>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true then
>> it will eagerly load all containment lists.
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> OK. I think I may have finally uncovered the real problem
>>>
>>> You're right about the association table. I had forgotten that I had
>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>> induces an association table. I did the same for the
>>> "Warfare.dependencies" reference and it appears to have solved the
>>> problem for the object with the null references. The annotation is:
>>>
>>> <eclass name="WarfareSystem">
>>> <property name="dependencies">
>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>> <cascade>MERGE</cascade>
>>> <cascade>PERSIST</cascade>
>>> </many-to-many>
>>> </property>
>>> </eclass>
>>>
>>> So it's the lazy loading that's the problem. Because the references
>>> aren't actually null, they're just waiting for me to call
>>> system.getDependencies() to be loaded from the DB.
>>>
>>> This poses a problem, however. I'm trying to serialize the object from
>>> the DB to a resource, and the EMF code doesn't do the nice thing and call
>>> system.getDependencies(), it just tries to persist what's already in
>>> memory. So I get the following error:
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>
>>> So there are two solutions:
>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>> serialization code call the appropriate methods to trigger hibernate to
>>> retrieve referenced objects.
>>> 2. I eagerly load everything (which is essentially every reference in my
>>> data model).
>>>
>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate to
>>> eagerly load *everything*?
>>>
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:fruplj$p6$1@build.eclipse.org...
>>>> Hi Daniel,
>>>> I think it is not a missing table (otherwise you would get a
>>>> hibernate/sql error). Afaics the association you are mentioning below is
>>>> not persisted using a join table but using a foreign key in the child
>>>> table.
>>>> A cause for having null values in a list is that a child got deleted
>>>> without removing it from the list of the parent. For example if you just
>>>> read the child from the db (and not the parent) and then remove the
>>>> child then hibernate won't update the indexes in the list. This results
>>>> in a hole in the indexes in the childs. When reading the contents of the
>>>> list hibernate will place null values in the list in the missing
>>>> locations. You can check this out by looking in the db and see if values
>>>> in the warfaresystem_dependencies_idx column are correct (no missing
>>>> values).
>>>>
>>>> If this is the cause then there are two solutions:
>>>> - change your code so that when removing the child it is also removed
>>>> from the parent
>>>> - change the mapping to a set/bag instead of a list, then the idx column
>>>> is not present. This is only possible if the order of the children is
>>>> not important. See here for more info:
>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>
>>>> gr. Martin
>>>>
>>>> Daniel Tuohy wrote:
>>>>> Hi Guys,
>>>>>
>>>>> I noticed that some references in my data (persisted with Teneo) were
>>>>> null when I reloaded them from the DB. I looked at the DB and found
>>>>> that I was inexplicably missing one of the association tables. The
>>>>> offending association is for the EMF-modeled type and reference
>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>> auto-genned hbm file is:
>>>>>
>>>>> <list name="dependencies" lazy="true">
>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>> not-null="false" unique="false"/>
>>>>> </key>
>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>> </list>
>>>>>
>>>>> The relevant mapping info message that is printed to console during the
>>>>> mapping is:
>>>>>
>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>
>>>>> Note that I have an analagous reference for another type that is being
>>>>> persisted correctly with it's own association table. The entry in the
>>>>> hbm file is identical (modulo the name/type of the reference), and the
>>>>> info message is:
>>>>>
>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>> Step.outputsTo -> step_outputsto
>>>>>
>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>> perform to get you more info?
>>>>>
>>>>> Daniel
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #615951 is a reply to message #115314] Sat, 22 March 2008 20:31 Go to previous message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
1. Yes, it fails on the first element in the list.
2. Yes. There are four elements in the list, and the last one is set, the
first three are null.
3. The list is a HibernatePersistableEList.
4. isLoaded() returns "true"

I should also note that I am now seeing inconsistent behavior. Sometimes
the list for the object is full of the correct references, sometimes the
first three are null and only the last is set, and sometimes the list is
actually empty.

The object being persisted is very elaborate, and the object whose
references are corrupted is contained within the object I'm trying to
serialize. The JUnit test I am running is not complicated, it consists of
object creation, persistence, retrieval, and serialization (failing on
serialization when it gets to these references).

Unfortunately, it concerns a great deal of data and a large EMF model, so I
will have to consult my employer before I can commit to sending over a test
case. Does anything further oc

"Martin Taal" <mtaal@elver.org> wrote in message
news:fs2lrj$nbg$1@build.eclipse.org...
>I agree that if you only do create, persist and reload that there should
>not be a hole-in-list
> situation.
> A few questions:
> - Does it fail on the first element in the list?
> - Are other parts of the list set?
> - What class is the list?
> - If it is one of the hibernate teneo list implementations, what does the
> isLoaded property say (just before the npe happens)?
>
> If you can make a (small) reproducible test then I can look at it also.
> You can send it to me directly by email (mtaal_at_elver.org).
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> So, in your estimation, there is no way EMF could be accessing those
>> references and not triggering lazy loading? I suspect that the
>> references are being retrieved using feature IDs, although I don't know
>> that would make a difference.
>>
>> As far as the holes-in-the-list conjecture, I should mention that I'm
>> literally creating the object, persisting it, reloading it and attempting
>> to serialize to a resource. There is no adding to or removal from any
>> list references going on. If this were the case, then I shouldn't be
>> seeing an inconsistency between the in-memory and persisted
>> representations, right?
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:frvhu0$ha9$1@build.eclipse.org...
>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>> loading, even without going through the getter the lazy loaded list
>>> should be automatically loaded when accessed (for example through an
>>> iterator) and not have null values. Afaics null values in the list point
>>> to the problem I described in my previous reply (holes in the list).
>>>
>>> Regarding eager loading, there is this option:
>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>> then it will eagerly load all containment lists.
>>>
>>> gr. Martin
>>>
>>> Daniel Tuohy wrote:
>>>> OK. I think I may have finally uncovered the real problem
>>>>
>>>> You're right about the association table. I had forgotten that I had
>>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>>> induces an association table. I did the same for the
>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>> problem for the object with the null references. The annotation is:
>>>>
>>>> <eclass name="WarfareSystem">
>>>> <property name="dependencies">
>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>> <cascade>MERGE</cascade>
>>>> <cascade>PERSIST</cascade>
>>>> </many-to-many>
>>>> </property>
>>>> </eclass>
>>>>
>>>> So it's the lazy loading that's the problem. Because the references
>>>> aren't actually null, they're just waiting for me to call
>>>> system.getDependencies() to be loaded from the DB.
>>>>
>>>> This poses a problem, however. I'm trying to serialize the object from
>>>> the DB to a resource, and the EMF code doesn't do the nice thing and
>>>> call system.getDependencies(), it just tries to persist what's already
>>>> in memory. So I get the following error:
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>> at
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>> at
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>
>>>> So there are two solutions:
>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>> serialization code call the appropriate methods to trigger hibernate to
>>>> retrieve referenced objects.
>>>> 2. I eagerly load everything (which is essentially every reference in
>>>> my data model).
>>>>
>>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate
>>>> to eagerly load *everything*?
>>>>
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>> Hi Daniel,
>>>>> I think it is not a missing table (otherwise you would get a
>>>>> hibernate/sql error). Afaics the association you are mentioning below
>>>>> is not persisted using a join table but using a foreign key in the
>>>>> child table.
>>>>> A cause for having null values in a list is that a child got deleted
>>>>> without removing it from the list of the parent. For example if you
>>>>> just read the child from the db (and not the parent) and then remove
>>>>> the child then hibernate won't update the indexes in the list. This
>>>>> results in a hole in the indexes in the childs. When reading the
>>>>> contents of the list hibernate will place null values in the list in
>>>>> the missing locations. You can check this out by looking in the db and
>>>>> see if values in the warfaresystem_dependencies_idx column are correct
>>>>> (no missing values).
>>>>>
>>>>> If this is the cause then there are two solutions:
>>>>> - change your code so that when removing the child it is also removed
>>>>> from the parent
>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>> column is not present. This is only possible if the order of the
>>>>> children is not important. See here for more info:
>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> Hi Guys,
>>>>>>
>>>>>> I noticed that some references in my data (persisted with Teneo) were
>>>>>> null when I reloaded them from the DB. I looked at the DB and found
>>>>>> that I was inexplicably missing one of the association tables. The
>>>>>> offending association is for the EMF-modeled type and reference
>>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>>> auto-genned hbm file is:
>>>>>>
>>>>>> <list name="dependencies" lazy="true">
>>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>> not-null="false" unique="false"/>
>>>>>> </key>
>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>> </list>
>>>>>>
>>>>>> The relevant mapping info message that is printed to console during
>>>>>> the mapping is:
>>>>>>
>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>>
>>>>>> Note that I have an analagous reference for another type that is
>>>>>> being persisted correctly with it's own association table. The entry
>>>>>> in the hbm file is identical (modulo the name/type of the reference),
>>>>>> and the info message is:
>>>>>>
>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>> Step.outputsTo -> step_outputsto
>>>>>>
>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>> perform to get you more info?
>>>>>>
>>>>>> Daniel
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #615952 is a reply to message #115367] Sat, 22 March 2008 20:37 Go to previous message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
Sorry, I sent that prematurely. It was meant to end: "Does anything further
occur to you in light of the answers to your questions, or due to the
inconsistency in the contents of that list?"

I should also note that I see this inconsistency only when I recreate the DB
and persist the object each time I run the test. If I just load the object
from the same DB repeatedly, the behavior is consistent.

"Daniel Tuohy" <danielr2e@gmail.com> wrote in message
news:fs3q7l$j5r$1@build.eclipse.org...
> 1. Yes, it fails on the first element in the list.
> 2. Yes. There are four elements in the list, and the last one is set,
> the first three are null.
> 3. The list is a HibernatePersistableEList.
> 4. isLoaded() returns "true"
>
> I should also note that I am now seeing inconsistent behavior. Sometimes
> the list for the object is full of the correct references, sometimes the
> first three are null and only the last is set, and sometimes the list is
> actually empty.
>
> The object being persisted is very elaborate, and the object whose
> references are corrupted is contained within the object I'm trying to
> serialize. The JUnit test I am running is not complicated, it consists of
> object creation, persistence, retrieval, and serialization (failing on
> serialization when it gets to these references).
>
> Unfortunately, it concerns a great deal of data and a large EMF model, so
> I will have to consult my employer before I can commit to sending over a
> test case. Does anything further oc
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fs2lrj$nbg$1@build.eclipse.org...
>>I agree that if you only do create, persist and reload that there should
>>not be a hole-in-list
>> situation.
>> A few questions:
>> - Does it fail on the first element in the list?
>> - Are other parts of the list set?
>> - What class is the list?
>> - If it is one of the hibernate teneo list implementations, what does the
>> isLoaded property say (just before the npe happens)?
>>
>> If you can make a (small) reproducible test then I can look at it also.
>> You can send it to me directly by email (mtaal_at_elver.org).
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> So, in your estimation, there is no way EMF could be accessing those
>>> references and not triggering lazy loading? I suspect that the
>>> references are being retrieved using feature IDs, although I don't know
>>> that would make a difference.
>>>
>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>> literally creating the object, persisting it, reloading it and
>>> attempting to serialize to a resource. There is no adding to or removal
>>> from any list references going on. If this were the case, then I
>>> shouldn't be seeing an inconsistency between the in-memory and persisted
>>> representations, right?
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>> loading, even without going through the getter the lazy loaded list
>>>> should be automatically loaded when accessed (for example through an
>>>> iterator) and not have null values. Afaics null values in the list
>>>> point to the problem I described in my previous reply (holes in the
>>>> list).
>>>>
>>>> Regarding eager loading, there is this option:
>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>> then it will eagerly load all containment lists.
>>>>
>>>> gr. Martin
>>>>
>>>> Daniel Tuohy wrote:
>>>>> OK. I think I may have finally uncovered the real problem
>>>>>
>>>>> You're right about the association table. I had forgotten that I had
>>>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>>>> induces an association table. I did the same for the
>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>> problem for the object with the null references. The annotation is:
>>>>>
>>>>> <eclass name="WarfareSystem">
>>>>> <property name="dependencies">
>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>> <cascade>MERGE</cascade>
>>>>> <cascade>PERSIST</cascade>
>>>>> </many-to-many>
>>>>> </property>
>>>>> </eclass>
>>>>>
>>>>> So it's the lazy loading that's the problem. Because the references
>>>>> aren't actually null, they're just waiting for me to call
>>>>> system.getDependencies() to be loaded from the DB.
>>>>>
>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>> from the DB to a resource, and the EMF code doesn't do the nice thing
>>>>> and call system.getDependencies(), it just tries to persist what's
>>>>> already in memory. So I get the following error:
>>>>>
>>>>> java.lang.NullPointerException
>>>>> at
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>> at
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>> at
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>
>>>>> So there are two solutions:
>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>> to retrieve referenced objects.
>>>>> 2. I eagerly load everything (which is essentially every reference in
>>>>> my data model).
>>>>>
>>>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate
>>>>> to eagerly load *everything*?
>>>>>
>>>>>
>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>> Hi Daniel,
>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>> hibernate/sql error). Afaics the association you are mentioning below
>>>>>> is not persisted using a join table but using a foreign key in the
>>>>>> child table.
>>>>>> A cause for having null values in a list is that a child got deleted
>>>>>> without removing it from the list of the parent. For example if you
>>>>>> just read the child from the db (and not the parent) and then remove
>>>>>> the child then hibernate won't update the indexes in the list. This
>>>>>> results in a hole in the indexes in the childs. When reading the
>>>>>> contents of the list hibernate will place null values in the list in
>>>>>> the missing locations. You can check this out by looking in the db
>>>>>> and see if values in the warfaresystem_dependencies_idx column are
>>>>>> correct (no missing values).
>>>>>>
>>>>>> If this is the cause then there are two solutions:
>>>>>> - change your code so that when removing the child it is also removed
>>>>>> from the parent
>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>> column is not present. This is only possible if the order of the
>>>>>> children is not important. See here for more info:
>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> Daniel Tuohy wrote:
>>>>>>> Hi Guys,
>>>>>>>
>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>> were null when I reloaded them from the DB. I looked at the DB and
>>>>>>> found that I was inexplicably missing one of the association tables.
>>>>>>> The offending association is for the EMF-modeled type and reference
>>>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>>>> auto-genned hbm file is:
>>>>>>>
>>>>>>> <list name="dependencies" lazy="true">
>>>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>> not-null="false" unique="false"/>
>>>>>>> </key>
>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>> </list>
>>>>>>>
>>>>>>> The relevant mapping info message that is printed to console during
>>>>>>> the mapping is:
>>>>>>>
>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>>>
>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>> being persisted correctly with it's own association table. The
>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>> reference), and the info message is:
>>>>>>>
>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>> Step.outputsTo -> step_outputsto
>>>>>>>
>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>> perform to get you more info?
>>>>>>>
>>>>>>> Daniel
>>>>>> --
>>>>>>
>>>>>> With Regards, Martin Taal
>>>>>>
>>>>>> Springsite/Elver.org
>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>> The Netherlands
>>>>>> 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
>>>>>
>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>>
>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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: [Teneo] Association table not created for one-to-many EMF reference [message #615954 is a reply to message #115380] Sun, 23 March 2008 08:54 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hmmm, looking back to your remark in the beginning, what is also possible is that the one-to-many is
really a many-to-many.
So what can happen is that the elements in one list are present in another list also. When the lists
are mapped using foreign keys then when lists are persisted a list which is persisted later will
overwrite the foreign keys of the elements of a first list. So depending on the order in which lists
are persisted, it results in empty entries. A simple setting to try this out can be to set the
following option to true:
PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS

then you should get jointables for all associations (except contained).

or you can force a jointable for individual associations with the jointable annotation:
@JoinTable(name="MyGreatJoinTable")

or use the many-to-many as you mention below.

gr. Martin

Daniel Tuohy wrote:
> Sorry, I sent that prematurely. It was meant to end: "Does anything further
> occur to you in light of the answers to your questions, or due to the
> inconsistency in the contents of that list?"
>
> I should also note that I see this inconsistency only when I recreate the DB
> and persist the object each time I run the test. If I just load the object
> from the same DB repeatedly, the behavior is consistent.
>
> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
> news:fs3q7l$j5r$1@build.eclipse.org...
>> 1. Yes, it fails on the first element in the list.
>> 2. Yes. There are four elements in the list, and the last one is set,
>> the first three are null.
>> 3. The list is a HibernatePersistableEList.
>> 4. isLoaded() returns "true"
>>
>> I should also note that I am now seeing inconsistent behavior. Sometimes
>> the list for the object is full of the correct references, sometimes the
>> first three are null and only the last is set, and sometimes the list is
>> actually empty.
>>
>> The object being persisted is very elaborate, and the object whose
>> references are corrupted is contained within the object I'm trying to
>> serialize. The JUnit test I am running is not complicated, it consists of
>> object creation, persistence, retrieval, and serialization (failing on
>> serialization when it gets to these references).
>>
>> Unfortunately, it concerns a great deal of data and a large EMF model, so
>> I will have to consult my employer before I can commit to sending over a
>> test case. Does anything further oc
>>
>> "Martin Taal" <mtaal@elver.org> wrote in message
>> news:fs2lrj$nbg$1@build.eclipse.org...
>>> I agree that if you only do create, persist and reload that there should
>>> not be a hole-in-list
>>> situation.
>>> A few questions:
>>> - Does it fail on the first element in the list?
>>> - Are other parts of the list set?
>>> - What class is the list?
>>> - If it is one of the hibernate teneo list implementations, what does the
>>> isLoaded property say (just before the npe happens)?
>>>
>>> If you can make a (small) reproducible test then I can look at it also.
>>> You can send it to me directly by email (mtaal_at_elver.org).
>>>
>>> gr. Martin
>>>
>>> Daniel Tuohy wrote:
>>>> So, in your estimation, there is no way EMF could be accessing those
>>>> references and not triggering lazy loading? I suspect that the
>>>> references are being retrieved using feature IDs, although I don't know
>>>> that would make a difference.
>>>>
>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>> literally creating the object, persisting it, reloading it and
>>>> attempting to serialize to a resource. There is no adding to or removal
>>>> from any list references going on. If this were the case, then I
>>>> shouldn't be seeing an inconsistency between the in-memory and persisted
>>>> representations, right?
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>> loading, even without going through the getter the lazy loaded list
>>>>> should be automatically loaded when accessed (for example through an
>>>>> iterator) and not have null values. Afaics null values in the list
>>>>> point to the problem I described in my previous reply (holes in the
>>>>> list).
>>>>>
>>>>> Regarding eager loading, there is this option:
>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>>> then it will eagerly load all containment lists.
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>
>>>>>> You're right about the association table. I had forgotten that I had
>>>>>> added an annotation for "Step.outputsTo" that (for whatever reason)
>>>>>> induces an association table. I did the same for the
>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>> problem for the object with the null references. The annotation is:
>>>>>>
>>>>>> <eclass name="WarfareSystem">
>>>>>> <property name="dependencies">
>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>> <cascade>MERGE</cascade>
>>>>>> <cascade>PERSIST</cascade>
>>>>>> </many-to-many>
>>>>>> </property>
>>>>>> </eclass>
>>>>>>
>>>>>> So it's the lazy loading that's the problem. Because the references
>>>>>> aren't actually null, they're just waiting for me to call
>>>>>> system.getDependencies() to be loaded from the DB.
>>>>>>
>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>> from the DB to a resource, and the EMF code doesn't do the nice thing
>>>>>> and call system.getDependencies(), it just tries to persist what's
>>>>>> already in memory. So I get the following error:
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> at
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>> at
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>> at
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>
>>>>>> So there are two solutions:
>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>>> to retrieve referenced objects.
>>>>>> 2. I eagerly load everything (which is essentially every reference in
>>>>>> my data model).
>>>>>>
>>>>>> If (2) is my only option, is there an easy way to tell Teneo/Hibernate
>>>>>> to eagerly load *everything*?
>>>>>>
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>> Hi Daniel,
>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>> hibernate/sql error). Afaics the association you are mentioning below
>>>>>>> is not persisted using a join table but using a foreign key in the
>>>>>>> child table.
>>>>>>> A cause for having null values in a list is that a child got deleted
>>>>>>> without removing it from the list of the parent. For example if you
>>>>>>> just read the child from the db (and not the parent) and then remove
>>>>>>> the child then hibernate won't update the indexes in the list. This
>>>>>>> results in a hole in the indexes in the childs. When reading the
>>>>>>> contents of the list hibernate will place null values in the list in
>>>>>>> the missing locations. You can check this out by looking in the db
>>>>>>> and see if values in the warfaresystem_dependencies_idx column are
>>>>>>> correct (no missing values).
>>>>>>>
>>>>>>> If this is the cause then there are two solutions:
>>>>>>> - change your code so that when removing the child it is also removed
>>>>>>> from the parent
>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>> column is not present. This is only possible if the order of the
>>>>>>> children is not important. See here for more info:
>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Daniel Tuohy wrote:
>>>>>>>> Hi Guys,
>>>>>>>>
>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>> were null when I reloaded them from the DB. I looked at the DB and
>>>>>>>> found that I was inexplicably missing one of the association tables.
>>>>>>>> The offending association is for the EMF-modeled type and reference
>>>>>>>> "WarfareSystem.dependencies". The corresponding entry in the
>>>>>>>> auto-genned hbm file is:
>>>>>>>>
>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>> <key update="true" foreign-key="warfaresystem_dependencies">
>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>> not-null="false" unique="false"/>
>>>>>>>> </key>
>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>> </list>
>>>>>>>>
>>>>>>>> The relevant mapping info message that is printed to console during
>>>>>>>> the mapping is:
>>>>>>>>
>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>>> WarfareSystem.dependencies -> warfaresystem
>>>>>>>>
>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>> reference), and the info message is:
>>>>>>>>
>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection:
>>>>>>>> Step.outputsTo -> step_outputsto
>>>>>>>>
>>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>>> perform to get you more info?
>>>>>>>>
>>>>>>>> Daniel
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>> --
>>>
>>> With Regards, Martin Taal
>>>
>>> Springsite/Elver.org
>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>> The Netherlands
>>> 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
>>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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: [Teneo] Association table not created for one-to-many EMF reference [message #615956 is a reply to message #115407] Sun, 23 March 2008 14:59 Go to previous message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
I think you're right. It hadn't occured to me that this association was
n-to-m, but indeed it is. Without using that PersistenceOption, I'm still
seeing the error on some other objects, but I would bet that I've simply
overlooked another many-to-many association in the model.

"Martin Taal" <mtaal@elver.org> wrote in message
news:fs55t8$mqh$1@build.eclipse.org...
> Hmmm, looking back to your remark in the beginning, what is also possible
> is that the one-to-many is really a many-to-many.
> So what can happen is that the elements in one list are present in another
> list also. When the lists are mapped using foreign keys then when lists
> are persisted a list which is persisted later will overwrite the foreign
> keys of the elements of a first list. So depending on the order in which
> lists are persisted, it results in empty entries. A simple setting to try
> this out can be to set the following option to true:
> PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
>
> then you should get jointables for all associations (except contained).
>
> or you can force a jointable for individual associations with the
> jointable annotation:
> @JoinTable(name="MyGreatJoinTable")
>
> or use the many-to-many as you mention below.
>
> gr. Martin
>
> Daniel Tuohy wrote:
>> Sorry, I sent that prematurely. It was meant to end: "Does anything
>> further occur to you in light of the answers to your questions, or due to
>> the inconsistency in the contents of that list?"
>>
>> I should also note that I see this inconsistency only when I recreate the
>> DB and persist the object each time I run the test. If I just load the
>> object from the same DB repeatedly, the behavior is consistent.
>>
>> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
>> news:fs3q7l$j5r$1@build.eclipse.org...
>>> 1. Yes, it fails on the first element in the list.
>>> 2. Yes. There are four elements in the list, and the last one is set,
>>> the first three are null.
>>> 3. The list is a HibernatePersistableEList.
>>> 4. isLoaded() returns "true"
>>>
>>> I should also note that I am now seeing inconsistent behavior.
>>> Sometimes the list for the object is full of the correct references,
>>> sometimes the first three are null and only the last is set, and
>>> sometimes the list is actually empty.
>>>
>>> The object being persisted is very elaborate, and the object whose
>>> references are corrupted is contained within the object I'm trying to
>>> serialize. The JUnit test I am running is not complicated, it consists
>>> of object creation, persistence, retrieval, and serialization (failing
>>> on serialization when it gets to these references).
>>>
>>> Unfortunately, it concerns a great deal of data and a large EMF model,
>>> so I will have to consult my employer before I can commit to sending
>>> over a test case. Does anything further oc
>>>
>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>> news:fs2lrj$nbg$1@build.eclipse.org...
>>>> I agree that if you only do create, persist and reload that there
>>>> should not be a hole-in-list
>>>> situation.
>>>> A few questions:
>>>> - Does it fail on the first element in the list?
>>>> - Are other parts of the list set?
>>>> - What class is the list?
>>>> - If it is one of the hibernate teneo list implementations, what does
>>>> the isLoaded property say (just before the npe happens)?
>>>>
>>>> If you can make a (small) reproducible test then I can look at it also.
>>>> You can send it to me directly by email (mtaal_at_elver.org).
>>>>
>>>> gr. Martin
>>>>
>>>> Daniel Tuohy wrote:
>>>>> So, in your estimation, there is no way EMF could be accessing those
>>>>> references and not triggering lazy loading? I suspect that the
>>>>> references are being retrieved using feature IDs, although I don't
>>>>> know that would make a difference.
>>>>>
>>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>>> literally creating the object, persisting it, reloading it and
>>>>> attempting to serialize to a resource. There is no adding to or
>>>>> removal from any list references going on. If this were the case,
>>>>> then I shouldn't be seeing an inconsistency between the in-memory and
>>>>> persisted representations, right?
>>>>>
>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>>> loading, even without going through the getter the lazy loaded list
>>>>>> should be automatically loaded when accessed (for example through an
>>>>>> iterator) and not have null values. Afaics null values in the list
>>>>>> point to the problem I described in my previous reply (holes in the
>>>>>> list).
>>>>>>
>>>>>> Regarding eager loading, there is this option:
>>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>>>> then it will eagerly load all containment lists.
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> Daniel Tuohy wrote:
>>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>>
>>>>>>> You're right about the association table. I had forgotten that I
>>>>>>> had added an annotation for "Step.outputsTo" that (for whatever
>>>>>>> reason) induces an association table. I did the same for the
>>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>>> problem for the object with the null references. The annotation is:
>>>>>>>
>>>>>>> <eclass name="WarfareSystem">
>>>>>>> <property name="dependencies">
>>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>>> <cascade>MERGE</cascade>
>>>>>>> <cascade>PERSIST</cascade>
>>>>>>> </many-to-many>
>>>>>>> </property>
>>>>>>> </eclass>
>>>>>>>
>>>>>>> So it's the lazy loading that's the problem. Because the references
>>>>>>> aren't actually null, they're just waiting for me to call
>>>>>>> system.getDependencies() to be loaded from the DB.
>>>>>>>
>>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>>> from the DB to a resource, and the EMF code doesn't do the nice
>>>>>>> thing and call system.getDependencies(), it just tries to persist
>>>>>>> what's already in memory. So I get the following error:
>>>>>>>
>>>>>>> java.lang.NullPointerException
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>>
>>>>>>> So there are two solutions:
>>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>>>> to retrieve referenced objects.
>>>>>>> 2. I eagerly load everything (which is essentially every reference
>>>>>>> in my data model).
>>>>>>>
>>>>>>> If (2) is my only option, is there an easy way to tell
>>>>>>> Teneo/Hibernate to eagerly load *everything*?
>>>>>>>
>>>>>>>
>>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>>> Hi Daniel,
>>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>>> hibernate/sql error). Afaics the association you are mentioning
>>>>>>>> below is not persisted using a join table but using a foreign key
>>>>>>>> in the child table.
>>>>>>>> A cause for having null values in a list is that a child got
>>>>>>>> deleted without removing it from the list of the parent. For
>>>>>>>> example if you just read the child from the db (and not the parent)
>>>>>>>> and then remove the child then hibernate won't update the indexes
>>>>>>>> in the list. This results in a hole in the indexes in the childs.
>>>>>>>> When reading the contents of the list hibernate will place null
>>>>>>>> values in the list in the missing locations. You can check this out
>>>>>>>> by looking in the db and see if values in the
>>>>>>>> warfaresystem_dependencies_idx column are correct (no missing
>>>>>>>> values).
>>>>>>>>
>>>>>>>> If this is the cause then there are two solutions:
>>>>>>>> - change your code so that when removing the child it is also
>>>>>>>> removed from the parent
>>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>>> column is not present. This is only possible if the order of the
>>>>>>>> children is not important. See here for more info:
>>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> Daniel Tuohy wrote:
>>>>>>>>> Hi Guys,
>>>>>>>>>
>>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>>> were null when I reloaded them from the DB. I looked at the DB
>>>>>>>>> and found that I was inexplicably missing one of the association
>>>>>>>>> tables. The offending association is for the EMF-modeled type and
>>>>>>>>> reference "WarfareSystem.dependencies". The corresponding entry
>>>>>>>>> in the auto-genned hbm file is:
>>>>>>>>>
>>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>>> <key update="true"
>>>>>>>>> foreign-key="warfaresystem_dependencies">
>>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>> </key>
>>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>>> </list>
>>>>>>>>>
>>>>>>>>> The relevant mapping info message that is printed to console
>>>>>>>>> during the mapping is:
>>>>>>>>>
>>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>> collection: WarfareSystem.dependencies -> warfaresystem
>>>>>>>>>
>>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>>> reference), and the info message is:
>>>>>>>>>
>>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>> collection: Step.outputsTo -> step_outputsto
>>>>>>>>>
>>>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>>>> perform to get you more info?
>>>>>>>>>
>>>>>>>>> Daniel
>>>>>>>> --
>>>>>>>>
>>>>>>>> With Regards, Martin Taal
>>>>>>>>
>>>>>>>> Springsite/Elver.org
>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>> The Netherlands
>>>>>>>> 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
>>>>>> --
>>>>>>
>>>>>> With Regards, Martin Taal
>>>>>>
>>>>>> Springsite/Elver.org
>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>> The Netherlands
>>>>>> 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
>>>>>
>>>>
>>>> --
>>>>
>>>> With Regards, Martin Taal
>>>>
>>>> Springsite/Elver.org
>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>> The Netherlands
>>>> 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
>>>
>>
>>
>
>
> --
>
> With Regards, Martin Taal
>
> Springsite/Elver.org
> Office: Hardwareweg 4, 3821 BV Amersfoort
> Postal: Nassaulaan 7, 3941 EC Doorn
> The Netherlands
> 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: [Teneo] Association table not created for one-to-many EMF reference [message #615957 is a reply to message #115436] Sun, 23 March 2008 15:01 Go to previous message
Daniel Tuohy is currently offline Daniel TuohyFriend
Messages: 41
Registered: July 2009
Member
And thanks so much for your help!

"Daniel Tuohy" <danielr2e@gmail.com> wrote in message
news:fs5r4g$s8q$1@build.eclipse.org...
>I think you're right. It hadn't occured to me that this association was
>n-to-m, but indeed it is. Without using that PersistenceOption, I'm still
>seeing the error on some other objects, but I would bet that I've simply
>overlooked another many-to-many association in the model.
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fs55t8$mqh$1@build.eclipse.org...
>> Hmmm, looking back to your remark in the beginning, what is also possible
>> is that the one-to-many is really a many-to-many.
>> So what can happen is that the elements in one list are present in
>> another list also. When the lists are mapped using foreign keys then when
>> lists are persisted a list which is persisted later will overwrite the
>> foreign keys of the elements of a first list. So depending on the order
>> in which lists are persisted, it results in empty entries. A simple
>> setting to try this out can be to set the following option to true:
>> PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
>>
>> then you should get jointables for all associations (except contained).
>>
>> or you can force a jointable for individual associations with the
>> jointable annotation:
>> @JoinTable(name="MyGreatJoinTable")
>>
>> or use the many-to-many as you mention below.
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> Sorry, I sent that prematurely. It was meant to end: "Does anything
>>> further occur to you in light of the answers to your questions, or due
>>> to the inconsistency in the contents of that list?"
>>>
>>> I should also note that I see this inconsistency only when I recreate
>>> the DB and persist the object each time I run the test. If I just load
>>> the object from the same DB repeatedly, the behavior is consistent.
>>>
>>> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
>>> news:fs3q7l$j5r$1@build.eclipse.org...
>>>> 1. Yes, it fails on the first element in the list.
>>>> 2. Yes. There are four elements in the list, and the last one is set,
>>>> the first three are null.
>>>> 3. The list is a HibernatePersistableEList.
>>>> 4. isLoaded() returns "true"
>>>>
>>>> I should also note that I am now seeing inconsistent behavior.
>>>> Sometimes the list for the object is full of the correct references,
>>>> sometimes the first three are null and only the last is set, and
>>>> sometimes the list is actually empty.
>>>>
>>>> The object being persisted is very elaborate, and the object whose
>>>> references are corrupted is contained within the object I'm trying to
>>>> serialize. The JUnit test I am running is not complicated, it consists
>>>> of object creation, persistence, retrieval, and serialization (failing
>>>> on serialization when it gets to these references).
>>>>
>>>> Unfortunately, it concerns a great deal of data and a large EMF model,
>>>> so I will have to consult my employer before I can commit to sending
>>>> over a test case. Does anything further oc
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:fs2lrj$nbg$1@build.eclipse.org...
>>>>> I agree that if you only do create, persist and reload that there
>>>>> should not be a hole-in-list
>>>>> situation.
>>>>> A few questions:
>>>>> - Does it fail on the first element in the list?
>>>>> - Are other parts of the list set?
>>>>> - What class is the list?
>>>>> - If it is one of the hibernate teneo list implementations, what does
>>>>> the isLoaded property say (just before the npe happens)?
>>>>>
>>>>> If you can make a (small) reproducible test then I can look at it
>>>>> also. You can send it to me directly by email (mtaal_at_elver.org).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> So, in your estimation, there is no way EMF could be accessing those
>>>>>> references and not triggering lazy loading? I suspect that the
>>>>>> references are being retrieved using feature IDs, although I don't
>>>>>> know that would make a difference.
>>>>>>
>>>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>>>> literally creating the object, persisting it, reloading it and
>>>>>> attempting to serialize to a resource. There is no adding to or
>>>>>> removal from any list references going on. If this were the case,
>>>>>> then I shouldn't be seeing an inconsistency between the in-memory and
>>>>>> persisted representations, right?
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>>>> loading, even without going through the getter the lazy loaded list
>>>>>>> should be automatically loaded when accessed (for example through an
>>>>>>> iterator) and not have null values. Afaics null values in the list
>>>>>>> point to the problem I described in my previous reply (holes in the
>>>>>>> list).
>>>>>>>
>>>>>>> Regarding eager loading, there is this option:
>>>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to
>>>>>>> true then it will eagerly load all containment lists.
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Daniel Tuohy wrote:
>>>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>>>
>>>>>>>> You're right about the association table. I had forgotten that I
>>>>>>>> had added an annotation for "Step.outputsTo" that (for whatever
>>>>>>>> reason) induces an association table. I did the same for the
>>>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>>>> problem for the object with the null references. The annotation
>>>>>>>> is:
>>>>>>>>
>>>>>>>> <eclass name="WarfareSystem">
>>>>>>>> <property name="dependencies">
>>>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>>>> <cascade>MERGE</cascade>
>>>>>>>> <cascade>PERSIST</cascade>
>>>>>>>> </many-to-many>
>>>>>>>> </property>
>>>>>>>> </eclass>
>>>>>>>>
>>>>>>>> So it's the lazy loading that's the problem. Because the
>>>>>>>> references aren't actually null, they're just waiting for me to
>>>>>>>> call system.getDependencies() to be loaded from the DB.
>>>>>>>>
>>>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>>>> from the DB to a resource, and the EMF code doesn't do the nice
>>>>>>>> thing and call system.getDependencies(), it just tries to persist
>>>>>>>> what's already in memory. So I get the following error:
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>>>
>>>>>>>> So there are two solutions:
>>>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>>>> serialization code call the appropriate methods to trigger
>>>>>>>> hibernate to retrieve referenced objects.
>>>>>>>> 2. I eagerly load everything (which is essentially every reference
>>>>>>>> in my data model).
>>>>>>>>
>>>>>>>> If (2) is my only option, is there an easy way to tell
>>>>>>>> Teneo/Hibernate to eagerly load *everything*?
>>>>>>>>
>>>>>>>>
>>>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>>>> Hi Daniel,
>>>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>>>> hibernate/sql error). Afaics the association you are mentioning
>>>>>>>>> below is not persisted using a join table but using a foreign key
>>>>>>>>> in the child table.
>>>>>>>>> A cause for having null values in a list is that a child got
>>>>>>>>> deleted without removing it from the list of the parent. For
>>>>>>>>> example if you just read the child from the db (and not the
>>>>>>>>> parent) and then remove the child then hibernate won't update the
>>>>>>>>> indexes in the list. This results in a hole in the indexes in the
>>>>>>>>> childs. When reading the contents of the list hibernate will place
>>>>>>>>> null values in the list in the missing locations. You can check
>>>>>>>>> this out by looking in the db and see if values in the
>>>>>>>>> warfaresystem_dependencies_idx column are correct (no missing
>>>>>>>>> values).
>>>>>>>>>
>>>>>>>>> If this is the cause then there are two solutions:
>>>>>>>>> - change your code so that when removing the child it is also
>>>>>>>>> removed from the parent
>>>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>>>> column is not present. This is only possible if the order of the
>>>>>>>>> children is not important. See here for more info:
>>>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> Daniel Tuohy wrote:
>>>>>>>>>> Hi Guys,
>>>>>>>>>>
>>>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>>>> were null when I reloaded them from the DB. I looked at the DB
>>>>>>>>>> and found that I was inexplicably missing one of the association
>>>>>>>>>> tables. The offending association is for the EMF-modeled type and
>>>>>>>>>> reference "WarfareSystem.dependencies". The corresponding entry
>>>>>>>>>> in the auto-genned hbm file is:
>>>>>>>>>>
>>>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>>>> <key update="true"
>>>>>>>>>> foreign-key="warfaresystem_dependencies">
>>>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>>>> </list>
>>>>>>>>>>
>>>>>>>>>> The relevant mapping info message that is printed to console
>>>>>>>>>> during the mapping is:
>>>>>>>>>>
>>>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: WarfareSystem.dependencies -> warfaresystem
>>>>>>>>>>
>>>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>>>> reference), and the info message is:
>>>>>>>>>>
>>>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: Step.outputsTo -> step_outputsto
>>>>>>>>>>
>>>>>>>>>> Which I believe is correct. Any idea why this might happen to
>>>>>>>>>> the "dependencies" reference? Are there any other diagnostics I
>>>>>>>>>> can perform to get you more info?
>>>>>>>>>>
>>>>>>>>>> Daniel
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> With Regards, Martin Taal
>>>>>>>>>
>>>>>>>>> Springsite/Elver.org
>>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>>> The Netherlands
>>>>>>>>> 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
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>>
>>>
>>>
>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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: [Teneo] Association table not created for one-to-many EMF reference [message #615963 is a reply to message #115436] Sun, 23 March 2008 20:19 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
It is good that I now know of this issue. I am considering of changing the option below to a default
value of true (so always have jointables). It seems to be a safer first approach. This will probably
be in the next release.

gr. Martin

Daniel Tuohy wrote:
> I think you're right. It hadn't occured to me that this association was
> n-to-m, but indeed it is. Without using that PersistenceOption, I'm still
> seeing the error on some other objects, but I would bet that I've simply
> overlooked another many-to-many association in the model.
>
> "Martin Taal" <mtaal@elver.org> wrote in message
> news:fs55t8$mqh$1@build.eclipse.org...
>> Hmmm, looking back to your remark in the beginning, what is also possible
>> is that the one-to-many is really a many-to-many.
>> So what can happen is that the elements in one list are present in another
>> list also. When the lists are mapped using foreign keys then when lists
>> are persisted a list which is persisted later will overwrite the foreign
>> keys of the elements of a first list. So depending on the order in which
>> lists are persisted, it results in empty entries. A simple setting to try
>> this out can be to set the following option to true:
>> PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS
>>
>> then you should get jointables for all associations (except contained).
>>
>> or you can force a jointable for individual associations with the
>> jointable annotation:
>> @JoinTable(name="MyGreatJoinTable")
>>
>> or use the many-to-many as you mention below.
>>
>> gr. Martin
>>
>> Daniel Tuohy wrote:
>>> Sorry, I sent that prematurely. It was meant to end: "Does anything
>>> further occur to you in light of the answers to your questions, or due to
>>> the inconsistency in the contents of that list?"
>>>
>>> I should also note that I see this inconsistency only when I recreate the
>>> DB and persist the object each time I run the test. If I just load the
>>> object from the same DB repeatedly, the behavior is consistent.
>>>
>>> "Daniel Tuohy" <danielr2e@gmail.com> wrote in message
>>> news:fs3q7l$j5r$1@build.eclipse.org...
>>>> 1. Yes, it fails on the first element in the list.
>>>> 2. Yes. There are four elements in the list, and the last one is set,
>>>> the first three are null.
>>>> 3. The list is a HibernatePersistableEList.
>>>> 4. isLoaded() returns "true"
>>>>
>>>> I should also note that I am now seeing inconsistent behavior.
>>>> Sometimes the list for the object is full of the correct references,
>>>> sometimes the first three are null and only the last is set, and
>>>> sometimes the list is actually empty.
>>>>
>>>> The object being persisted is very elaborate, and the object whose
>>>> references are corrupted is contained within the object I'm trying to
>>>> serialize. The JUnit test I am running is not complicated, it consists
>>>> of object creation, persistence, retrieval, and serialization (failing
>>>> on serialization when it gets to these references).
>>>>
>>>> Unfortunately, it concerns a great deal of data and a large EMF model,
>>>> so I will have to consult my employer before I can commit to sending
>>>> over a test case. Does anything further oc
>>>>
>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>> news:fs2lrj$nbg$1@build.eclipse.org...
>>>>> I agree that if you only do create, persist and reload that there
>>>>> should not be a hole-in-list
>>>>> situation.
>>>>> A few questions:
>>>>> - Does it fail on the first element in the list?
>>>>> - Are other parts of the list set?
>>>>> - What class is the list?
>>>>> - If it is one of the hibernate teneo list implementations, what does
>>>>> the isLoaded property say (just before the npe happens)?
>>>>>
>>>>> If you can make a (small) reproducible test then I can look at it also.
>>>>> You can send it to me directly by email (mtaal_at_elver.org).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> Daniel Tuohy wrote:
>>>>>> So, in your estimation, there is no way EMF could be accessing those
>>>>>> references and not triggering lazy loading? I suspect that the
>>>>>> references are being retrieved using feature IDs, although I don't
>>>>>> know that would make a difference.
>>>>>>
>>>>>> As far as the holes-in-the-list conjecture, I should mention that I'm
>>>>>> literally creating the object, persisting it, reloading it and
>>>>>> attempting to serialize to a resource. There is no adding to or
>>>>>> removal from any list references going on. If this were the case,
>>>>>> then I shouldn't be seeing an inconsistency between the in-memory and
>>>>>> persisted representations, right?
>>>>>>
>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>> news:frvhu0$ha9$1@build.eclipse.org...
>>>>>>> I am not sure why the many-to-many solved your npe. Regarding lazy
>>>>>>> loading, even without going through the getter the lazy loaded list
>>>>>>> should be automatically loaded when accessed (for example through an
>>>>>>> iterator) and not have null values. Afaics null values in the list
>>>>>>> point to the problem I described in my previous reply (holes in the
>>>>>>> list).
>>>>>>>
>>>>>>> Regarding eager loading, there is this option:
>>>>>>> PersistenceOptions.FETCH_CONTAINMENT_EAGERLY, if you set this to true
>>>>>>> then it will eagerly load all containment lists.
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> Daniel Tuohy wrote:
>>>>>>>> OK. I think I may have finally uncovered the real problem
>>>>>>>>
>>>>>>>> You're right about the association table. I had forgotten that I
>>>>>>>> had added an annotation for "Step.outputsTo" that (for whatever
>>>>>>>> reason) induces an association table. I did the same for the
>>>>>>>> "Warfare.dependencies" reference and it appears to have solved the
>>>>>>>> problem for the object with the null references. The annotation is:
>>>>>>>>
>>>>>>>> <eclass name="WarfareSystem">
>>>>>>>> <property name="dependencies">
>>>>>>>> <many-to-many fetch="EAGER" target-entity="WarfareSystem">
>>>>>>>> <cascade>MERGE</cascade>
>>>>>>>> <cascade>PERSIST</cascade>
>>>>>>>> </many-to-many>
>>>>>>>> </property>
>>>>>>>> </eclass>
>>>>>>>>
>>>>>>>> So it's the lazy loading that's the problem. Because the references
>>>>>>>> aren't actually null, they're just waiting for me to call
>>>>>>>> system.getDependencies() to be loaded from the DB.
>>>>>>>>
>>>>>>>> This poses a problem, however. I'm trying to serialize the object
>>>>>>>> from the DB to a resource, and the EMF code doesn't do the nice
>>>>>>>> thing and call system.getDependencies(), it just tries to persist
>>>>>>>> what's already in memory. So I get the following error:
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelp erImpl.java:781)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectMany(X MLSaveImpl.java:1842)
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1277)
>>>>>>>>
>>>>>>>> So there are two solutions:
>>>>>>>> 1. I find some way (or petition the EMF guys) to make the EMF
>>>>>>>> serialization code call the appropriate methods to trigger hibernate
>>>>>>>> to retrieve referenced objects.
>>>>>>>> 2. I eagerly load everything (which is essentially every reference
>>>>>>>> in my data model).
>>>>>>>>
>>>>>>>> If (2) is my only option, is there an easy way to tell
>>>>>>>> Teneo/Hibernate to eagerly load *everything*?
>>>>>>>>
>>>>>>>>
>>>>>>>> "Martin Taal" <mtaal@elver.org> wrote in message
>>>>>>>> news:fruplj$p6$1@build.eclipse.org...
>>>>>>>>> Hi Daniel,
>>>>>>>>> I think it is not a missing table (otherwise you would get a
>>>>>>>>> hibernate/sql error). Afaics the association you are mentioning
>>>>>>>>> below is not persisted using a join table but using a foreign key
>>>>>>>>> in the child table.
>>>>>>>>> A cause for having null values in a list is that a child got
>>>>>>>>> deleted without removing it from the list of the parent. For
>>>>>>>>> example if you just read the child from the db (and not the parent)
>>>>>>>>> and then remove the child then hibernate won't update the indexes
>>>>>>>>> in the list. This results in a hole in the indexes in the childs.
>>>>>>>>> When reading the contents of the list hibernate will place null
>>>>>>>>> values in the list in the missing locations. You can check this out
>>>>>>>>> by looking in the db and see if values in the
>>>>>>>>> warfaresystem_dependencies_idx column are correct (no missing
>>>>>>>>> values).
>>>>>>>>>
>>>>>>>>> If this is the cause then there are two solutions:
>>>>>>>>> - change your code so that when removing the child it is also
>>>>>>>>> removed from the parent
>>>>>>>>> - change the mapping to a set/bag instead of a list, then the idx
>>>>>>>>> column is not present. This is only possible if the order of the
>>>>>>>>> children is not important. See here for more info:
>>>>>>>>> http://www.elver.org/hibernate/hibernate_relations.html#Mapp ing+non-indexed+relations
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> Daniel Tuohy wrote:
>>>>>>>>>> Hi Guys,
>>>>>>>>>>
>>>>>>>>>> I noticed that some references in my data (persisted with Teneo)
>>>>>>>>>> were null when I reloaded them from the DB. I looked at the DB
>>>>>>>>>> and found that I was inexplicably missing one of the association
>>>>>>>>>> tables. The offending association is for the EMF-modeled type and
>>>>>>>>>> reference "WarfareSystem.dependencies". The corresponding entry
>>>>>>>>>> in the auto-genned hbm file is:
>>>>>>>>>>
>>>>>>>>>> <list name="dependencies" lazy="true">
>>>>>>>>>> <key update="true"
>>>>>>>>>> foreign-key="warfaresystem_dependencies">
>>>>>>>>>> <column name="`warfaresystem_dependencies_e_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <list-index column="`warfaresystem_dependencies_idx`"/>
>>>>>>>>>> <one-to-many entity-name="WarfareSystem"/>
>>>>>>>>>> </list>
>>>>>>>>>>
>>>>>>>>>> The relevant mapping info message that is printed to console
>>>>>>>>>> during the mapping is:
>>>>>>>>>>
>>>>>>>>>> 1969 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: WarfareSystem.dependencies -> warfaresystem
>>>>>>>>>>
>>>>>>>>>> Note that I have an analagous reference for another type that is
>>>>>>>>>> being persisted correctly with it's own association table. The
>>>>>>>>>> entry in the hbm file is identical (modulo the name/type of the
>>>>>>>>>> reference), and the info message is:
>>>>>>>>>>
>>>>>>>>>> 1938 [main] INFO org.hibernate.cfg.HbmBinder - Mapping
>>>>>>>>>> collection: Step.outputsTo -> step_outputsto
>>>>>>>>>>
>>>>>>>>>> Which I believe is correct. Any idea why this might happen to the
>>>>>>>>>> "dependencies" reference? Are there any other diagnostics I can
>>>>>>>>>> perform to get you more info?
>>>>>>>>>>
>>>>>>>>>> Daniel
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> With Regards, Martin Taal
>>>>>>>>>
>>>>>>>>> Springsite/Elver.org
>>>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>>>> The Netherlands
>>>>>>>>> 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
>>>>>>> --
>>>>>>>
>>>>>>> With Regards, Martin Taal
>>>>>>>
>>>>>>> Springsite/Elver.org
>>>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>>>> The Netherlands
>>>>>>> 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
>>>>> --
>>>>>
>>>>> With Regards, Martin Taal
>>>>>
>>>>> Springsite/Elver.org
>>>>> Office: Hardwareweg 4, 3821 BV Amersfoort
>>>>> Postal: Nassaulaan 7, 3941 EC Doorn
>>>>> The Netherlands
>>>>> 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
>>>
>>
>> --
>>
>> With Regards, Martin Taal
>>
>> Springsite/Elver.org
>> Office: Hardwareweg 4, 3821 BV Amersfoort
>> Postal: Nassaulaan 7, 3941 EC Doorn
>> The Netherlands
>> 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
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
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:Update database schema with Teneo/Hibernate
Next Topic:Update database schema with Teneo/Hibernate
Goto Forum:
  


Current Time: Wed Jun 23 07:02:02 GMT 2021

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

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

Back to the top