Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [texo] [teneo]? Support for opposites
[texo] [teneo]? Support for opposites [message #1131746] Thu, 10 October 2013 19:32 Go to next message
Miles Parker is currently offline Miles Parker
Messages: 1340
Registered: July 2009
Senior Member
Hi,

In my Texo implementation it doesn't appear that opposites definitions are being respected. That is, if I set book.setLibrary I would expect that I wouldn't need to do myLibrary.getBooks().add(book). However, when I persist the entities, and then retrieve them, only the value for the book.library is being set. It seem that under the covers, the while the Book library column is being set, a row is not being created in library_book for the pair.

Perhaps I have something misconfigured here..?

cheers,

Miles
Re: [texo] [teneo]? Support for opposites [message #1131758 is a reply to message #1131746] Thu, 10 October 2013 19:41 Go to previous messageGo to next message
Miles Parker is currently offline Miles Parker
Messages: 1340
Registered: July 2009
Senior Member
Actually, it seems weirder than that. If I try to set the opposite value myself, I get an error, e.g.:

Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "library_book"
  Detail: Key (library_db_id, book_db_id)=(454, 1001) already exists.
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:831)
	... 49 more


Whereas if I don't do the book.setLibrary, I get the opposite issue -- now the library_book row is populated, but the book.library column is not. So it appears that there is no way to set both!
Re: [texo] [teneo]? Support for opposites [message #1131847 is a reply to message #1131758] Thu, 10 October 2013 21:05 Go to previous messageGo to next message
Miles Parker is currently offline Miles Parker
Messages: 1340
Registered: July 2009
Senior Member
I made some progress on this. First, I had forgotten that the generated orm doesn't remove old annotations for existing classes (I think there is already a bug there) so I had both a ManyToOn and OneToMany annotation for the same reference. Then after fixing that, I discovered that I wasn't testing for having an object already added to list, which was causing the problem above. I believe that EMF does check for duplicates, but I'm not sure.

So now at least I can get the behaviour I want -- however, the opposite relation still doesn't appear to be working. And actually, looking at the generated model code I'm not sure how it could. So perhaps this is a feature request / bug report?
Re: [texo] [teneo]? Support for opposites [message #1131949 is a reply to message #1131847] Thu, 10 October 2013 22:36 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Miles,
The default list implementation used by Texo does not check for duplicates.

For the opposite relation not working, are you setting both sides explicitly? Or are you making use of the bidirectional
api/option from Texo:
http://wiki.eclipse.org/Texo/Code_Generation_Patterns#Generation_of_a_safe_bi-directional_association_API_.28or_not.29

Can you post/link the Book/Library java files and the orm file?

gr, Martin

On 10/10/2013 11:05 PM, Miles Parker wrote:
> I made some progress on this. First, I had forgotten that the generated orm doesn't remove old annotations for existing
> classes (I think there is already a bug there) so I had both a ManyToOn and OneToMany annotation for the same reference.
> Then after fixing that, I discovered that I wasn't testing for having an object already added to list, which was causing
> the problem above. I believe that EMF does check for duplicates, but I'm not sure.
>
> So now at least I can get the behaviour I want -- however, the opposite relation still doesn't appear to be working. And
> actually, looking at the generated model code I'm not sure how it could. So perhaps this is a feature request / bug report?


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [texo] [teneo]? Support for opposites [message #1142642 is a reply to message #1131949] Thu, 17 October 2013 19:24 Go to previous messageGo to next message
Miles Parker is currently offline Miles Parker
Messages: 1340
Registered: July 2009
Senior Member
Hi Martin...

Martin Taal wrote on Thu, 10 October 2013 18:36
Hi Miles,
For the opposite relation not working, are you setting both sides explicitly? Or are you making use of the bidirectional
api/option from Texo:


I was not making use of the bi-directional API, but just assuming that it would happen automatically. As mentioned above, I got it working by doing both, but I could use the API as well. So I think I'm good here. Still, would be nice to support this from standard list API for opposites as EMF does.
Re: [texo] [teneo]? Support for opposites [message #1142815 is a reply to message #1142642] Thu, 17 October 2013 21:49 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5339
Registered: July 2009
Senior Member
Hi Miles,
Yes I see your point, the 'problem' is that Texo really tries to use only standard java list/set implementations which
do not support bidirectional behavior.

gr. Martin

On 10/17/2013 09:24 PM, Miles Parker wrote:
> Hi Martin...
>
> Martin Taal wrote on Thu, 10 October 2013 18:36
>> Hi Miles,
>> For the opposite relation not working, are you setting both sides explicitly? Or are you making use of the
>> bidirectional api/option from Texo:
>
>
> I was not making use of the bi-directional API, but just assuming that it would happen automatically. As mentioned
> above, I got it working by doing both, but I could use the API as well. So I think I'm good here. Still, would be nice
> to support this from standard list API for opposites as EMF does.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:[TEXO] Failed to create the FK
Next Topic:XCORE and XTEXT Grammar
Goto Forum:
  


Current Time: Fri Oct 31 19:33:28 GMT 2014

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

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