Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » problem with object in mulitple lists
problem with object in mulitple lists [message #86473] Thu, 14 June 2007 15:17 Go to next message
Paul Gardiner is currently offline Paul GardinerFriend
Messages: 94
Registered: July 2009
Member
I have a case where TypeC extends TypeB, which extends TypeA. TypeC has an
EList<TypeB> getter method. If I have two instances of TypeC, and add the
same instance of TypeB to the ELists in both instances of TypeC, it doesn't
work. The first TypeC's EList has the position where the TypeB object
should have been set to null.

I created a test using the names listed above, created two TypeB objects
named TestNameB1 and TestNameB2, and then added both to an instance of
TypeC, and only TestNameB1 to a second instance of TypeC. Here is the
output when I spit them out to the console. The "members" is a println of
the EList.

typeC:com.syntellect.test.model.impl.TypeCImpl@178655 (name: TestNameC1)
members:[[null, com.syntellect.test.model.impl.TypeBImpl@1be4663 (name:
TestNameB2) (someData: Some test data2)]]
typeC:com.syntellect.test.model.impl.TypeCImpl@746ad0 (name: TestNameC2)
members:[[com.syntellect.test.model.impl.TypeBImpl@d8a1a0 (name:
TestNameB1) (someData: Some test data1)]]

Note the null in the first position of the first TypeC's list. If don't add
TestNameB1 to the second TypeC, the first position is filled fine, as it
should be.

Thanks,
Paul
Re: problem with object in mulitple lists [message #86490 is a reply to message #86473] Thu, 14 June 2007 19:12 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
The following is probably the cause, the reference from the table of B to C is modeled in tableB as
a foreign key, this foreign key can only have one value so when saving both c's the second one wins.
Because this happens hidden for hibernate the index of the second element in the first c's list is
not corrected to one, resulting in the null element at index 0.

To prevent this a join table should be used for this reference, there are several ways to accomplish
this;
1) add a @JoinTable annotation to the ereference
2) http://www.elver.org/hibernate/hibernate_relations.html#Forc e+a+join+table+for+1%3An+relations
3) Set the option: PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS to true

gr. Martin

Paul Gardiner wrote:
> I have a case where TypeC extends TypeB, which extends TypeA. TypeC has an
> EList<TypeB> getter method. If I have two instances of TypeC, and add the
> same instance of TypeB to the ELists in both instances of TypeC, it doesn't
> work. The first TypeC's EList has the position where the TypeB object
> should have been set to null.
>
> I created a test using the names listed above, created two TypeB objects
> named TestNameB1 and TestNameB2, and then added both to an instance of
> TypeC, and only TestNameB1 to a second instance of TypeC. Here is the
> output when I spit them out to the console. The "members" is a println of
> the EList.
>
> typeC:com.syntellect.test.model.impl.TypeCImpl@178655 (name: TestNameC1)
> members:[[null, com.syntellect.test.model.impl.TypeBImpl@1be4663 (name:
> TestNameB2) (someData: Some test data2)]]
> typeC:com.syntellect.test.model.impl.TypeCImpl@746ad0 (name: TestNameC2)
> members:[[com.syntellect.test.model.impl.TypeBImpl@d8a1a0 (name:
> TestNameB1) (someData: Some test data1)]]
>
> Note the null in the first position of the first TypeC's list. If don't add
> TestNameB1 to the second TypeC, the first position is filled fine, as it
> should be.
>
> Thanks,
> Paul
>
>



--

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: problem with object in mulitple lists [message #606992 is a reply to message #86473] Thu, 14 June 2007 19:12 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
The following is probably the cause, the reference from the table of B to C is modeled in tableB as
a foreign key, this foreign key can only have one value so when saving both c's the second one wins.
Because this happens hidden for hibernate the index of the second element in the first c's list is
not corrected to one, resulting in the null element at index 0.

To prevent this a join table should be used for this reference, there are several ways to accomplish
this;
1) add a @JoinTable annotation to the ereference
2) http://www.elver.org/hibernate/hibernate_relations.html#Forc e+a+join+table+for+1%3An+relations
3) Set the option: PersistenceOptions.JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS to true

gr. Martin

Paul Gardiner wrote:
> I have a case where TypeC extends TypeB, which extends TypeA. TypeC has an
> EList<TypeB> getter method. If I have two instances of TypeC, and add the
> same instance of TypeB to the ELists in both instances of TypeC, it doesn't
> work. The first TypeC's EList has the position where the TypeB object
> should have been set to null.
>
> I created a test using the names listed above, created two TypeB objects
> named TestNameB1 and TestNameB2, and then added both to an instance of
> TypeC, and only TestNameB1 to a second instance of TypeC. Here is the
> output when I spit them out to the console. The "members" is a println of
> the EList.
>
> typeC:com.syntellect.test.model.impl.TypeCImpl@178655 (name: TestNameC1)
> members:[[null, com.syntellect.test.model.impl.TypeBImpl@1be4663 (name:
> TestNameB2) (someData: Some test data2)]]
> typeC:com.syntellect.test.model.impl.TypeCImpl@746ad0 (name: TestNameC2)
> members:[[com.syntellect.test.model.impl.TypeBImpl@d8a1a0 (name:
> TestNameB1) (someData: Some test data1)]]
>
> Note the null in the first position of the first TypeC's list. If don't add
> TestNameB1 to the second TypeC, the first position is filled fine, as it
> should be.
>
> Thanks,
> Paul
>
>



--

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:problem with object in mulitple lists
Next Topic:[teneo/jpox] Question of design of metadata
Goto Forum:
  


Current Time: Thu Mar 28 11:23:10 GMT 2024

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

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

Back to the top