Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] Ordered bidirecional relationship, join colums and mapped by
[Texo] Ordered bidirecional relationship, join colums and mapped by [message #1257260] Wed, 26 February 2014 08:17 Go to next message
Cristian Prevedello is currently offline Cristian PrevedelloFriend
Messages: 33
Registered: June 2011
Member
Greetings all,

We have been using for a while teneo and now would like to move to texo, first tests case are positive, but we have a small issue with ordered bidirectional relationships.

As documentation says

--- CUT
When bi-directional ereferences are ordered (which is the default), i.e. when a java.util.List is used in the generated java code, then the ereferences will be mapped separately with join-columns on both sides of the assocation. So bi-directional ordered associations are not mapped using mapped-by and will use 2 foreign key associations.
--- CUT

Is this behaviour overridable in some way? We want ordered relationship (ie we want use list) but we want to use mappedby and don't want two join colums on the relationship.

So far we are removing the @joinColum annotation on the unwanted end with an ant script, but this is far from being ideal.


thank you.

[Updated on: Wed, 26 February 2014 08:26]

Report message to a moderator

Re: Ordered bidirecional relationship, join colums and mapped by [message #1257820 is a reply to message #1257260] Wed, 26 February 2014 20:42 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Cristian,
The reason behind this is that to maintain the order on both sides, then on both sides an index column is needed. So if
you want to use mapped by then you would loose the ordering in one direction as then there would not be a separate index
column for the non-mappped side.

Have you tried the mapped by annotation in the annotations model?

gr. Martin

On 02/26/2014 09:17 AM, Cristian Prevedello wrote:
> Greetings all,
>
> We have been using for a while teneo and now would like to move to texo, first tests case are positive, but we have a
> small issue with ordered bidirectional relationships.
>
> As documentation says
>
> --- CUT
> When bi-directional ereferences are ordered (which is the default), i.e. when a java.util.List is used in the generated
> java code, then the ereferences will be mapped separately with join-columns on both sides of the assocation. So
> bi-directional ordered associations are not mapped using mapped-by and will use 2 foreign key associations.
> --- CUT
>
> Is this behaviour overridable in some way? We want ordered relationship (ie we want use list) but we want to use
> mappedby and don't want two join colums on the relationship.
>
> So far we are removing the @joinColum annotation on the unwanted end with an ant script, but this is far from being ideal.
>
>
> thank you.
>
>


--

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] Ordered bidirecional relationship, join colums and mapped by [message #1258793 is a reply to message #1257260] Thu, 27 February 2014 19:19 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian PrevedelloFriend
Messages: 33
Registered: June 2011
Member
Thank you for your prompt reply, as usual Smile

Yes we tried to put a mappedby annotation, but jpa complains a mappedby can't exist with a @JoinColoumn annotation ( Caused by: org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn)


This is part of the model:

http://s28.postimg.org/q92lpati1/Cattura.jpg

The User class has the following member

@OneToMany(cascade = { CascadeType.ALL })
@JoinColumns({ @JoinColumn(name = "User_UserGroups") })
private List<UserGroup> userGroups = new ArrayList<UserGroup>();

The Group class has the following member

@OneToMany(cascade = { CascadeType.ALL })
@JoinColumns({ @JoinColumn(name = "Group_UserGroups") })
private List<UserGroup> userGroups = new ArrayList<UserGroup>();

and finally the UserGroup class has the following member

@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
@JoinColumns({ @JoinColumn(name = "UserGroup_User") })
private User user = null;


@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
@JoinColumns({ @JoinColumn(name = "UserGroup_Group") })
private Group group = null;


The resulting usergroup table has four foreign keys

http://s28.postimg.org/nvyg3ij89/Cattura.jpg

if i remove the @Joincolum on the user class and on the group class and set the mappedBy, the usergroup table has just two foreign key as expected.

Of course if i don't use list but Set the usergroup table has just two foreign keys as well.

am i doing wrong or this is the expected behaviour?

thank you!

Re: [Texo] Ordered bidirecional relationship, join colums and mapped by [message #1258902 is a reply to message #1258793] Thu, 27 February 2014 21:56 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Cristian,
So if I understand it correctly, if you set mappedby in the annotations model Texo still generates the joincolumn
annotations?

If that's the case then I can change this in Texo.

Another thing you can try is to set the same join column names for both sides of the association (so both sides use the
same join column). Using the annotationsmodel.

gr. Martin

On 02/27/2014 08:19 PM, Cristian Prevedello wrote:
> Thank you for your prompt reply, as usual :)
>
> Yes we tried to put a mappedby annotation, but jpa complains a mappedby can't exist with a @JoinColoumn annotation (
> Caused by: org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like
> @JoinTable or @JoinColumn)
>
>
> This is part of the model:
>
> http://postimg.org/image/q92lpati1/
>
> The User class has the following member
>
> @OneToMany(cascade = { CascadeType.ALL })
> @JoinColumns({ @JoinColumn(name = "User_UserGroups") })
> private List<UserGroup> userGroups = new ArrayList<UserGroup>();
>
> The Group class has the following member
>
> @OneToMany(cascade = { CascadeType.ALL })
> @JoinColumns({ @JoinColumn(name = "Group_UserGroups") })
> private List<UserGroup> userGroups = new ArrayList<UserGroup>();
>
> and finally the UserGroup class has the following member
>
> @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
> @JoinColumns({ @JoinColumn(name = "UserGroup_User") })
> private User user = null;
>
>
> @ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
> @JoinColumns({ @JoinColumn(name = "UserGroup_Group") })
> private Group group = null;
>
>
> The resulting usergroup table has four foreign keys
>
> http://postimg.org/image/nvyg3ij89/
>
> if i remove the @Joincolum on the user class and on the group class and set the mappedBy, the usergroup table has just
> two foreign key as expected.
> Of course if i don't use list but Set the usergroup table has just two foreign keys as well.
>
> am i doing wrong or this is the expected behaviour?
>
> thank you!
>
>


--

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] Ordered bidirecional relationship, join colums and mapped by [message #1259344 is a reply to message #1258902] Fri, 28 February 2014 09:24 Go to previous messageGo to next message
Cristian Prevedello is currently offline Cristian PrevedelloFriend
Messages: 33
Registered: June 2011
Member
Well, avoiding JoinColumn annotation in presence of the mappedBy one would be perfect and would compliant JPA entities.

best regards.

Re: [Texo] Ordered bidirecional relationship, join colums and mapped by [message #1259547 is a reply to message #1259344] Fri, 28 February 2014 14:12 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Yes indeed that for sure should change, can you enter a bugzilla for this?

gr. Martin

On 02/28/2014 10:24 AM, Cristian Prevedello wrote:
> Well, avoiding JoinColumn annotation in presence of the mappedBy one would be perfect and would compliant JPA entities.
>
> best regards.
>
>


--

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] Ordered bidirecional relationship, join colums and mapped by [message #1265157 is a reply to message #1259547] Wed, 05 March 2014 19:39 Go to previous message
Cristian Prevedello is currently offline Cristian PrevedelloFriend
Messages: 33
Registered: June 2011
Member
sorry for the delay...been crazy days.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=429701
Previous Topic:Create a dynamic custom control
Next Topic:Refering xcore from EMFatic file
Goto Forum:
  


Current Time: Fri Apr 19 16:32:33 GMT 2024

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

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

Back to the top