Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » Re: Texo: how to declare one-to-many relations for different parent types?
Re: Texo: how to declare one-to-many relations for different parent types? [message #872136] |
Tue, 15 May 2012 14:16 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Olaf,
This is not possible in relational database, a column can only reference one other table, so not multiple tables. So
these 3 foreign keys need 3 different columns. If class1/2/3 inherit from the same parent class then you could put the
matchSet in that parent class, if it makes functionally sense ofcourse.
Emft has this newsgroup link: news://news.eclipse.org/eclipse.technology.emft
and this forum link: www.eclipse.org/forums/eclipse.technology.emft
gr. Martin
On 05/15/2012 03:59 PM, Olaf Burdziakowski wrote:
> Martin you are right I was not precise enough. My example was about the ABC (MatchSetType). So: again:
>
> Class1 one many MatchSetType Class2 one many MatchSetType Class3 one many MatchSetType
> in side Class1 and Class2 and Class3 there is such part:
>
> @OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
> @OrderColumn(name = "ind")
> @JoinColumns({ @JoinColumn() })
> private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
>
> The problem is that the table of MatchSetType has foreign key to Class1 AND Class2 AND Class3 set.
>
> I would like to have hthe table of MatchSetType be able to have references to Class1 OR Class2 OR Class3.
>
> How to define this?
> (Where in EMFT is the discussion?)
--
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: how to declare one-to-many relations for different parent types? [message #872502 is a reply to message #872477] |
Wed, 16 May 2012 08:35 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Olaf,
Hmm, I don't understand yet... afaics the join table now has several columns to match class1/2/3 to the other side. How
many columns does the MS2ST table? And what are their foreign key constraints?
gr. Martin
On 05/16/2012 09:41 AM, Olaf Burdziakowski wrote:
> We found the solution:all we need to declare is:
>
> @OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
> @JoinTable(
> name="MS2ST",
> joinColumns = @JoinColumn( name="st_id"),
> inverseJoinColumns = @JoinColumn( name="ms_id")
> )
> @OrderColumn(name = "ind")
> private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
>
> So instead:
> @JoinColumns({ @JoinColumn() })
>
> There should be defined:
> @JoinTable( name="MS2ST", joinColumns = @JoinColumn( name="st_id"), inverseJoinColumns = @JoinColumn( name="ms_id"))
--
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: how to declare one-to-many relations for different parent types? [message #872619 is a reply to message #872502] |
Wed, 16 May 2012 13:25 |
Olaf Burdziakowski Messages: 46 Registered: April 2012 |
Member |
|
|
The solution is according to this explanation: http://www.mkyong.com/hibernate/hibernate-one-to-many-relationship-example-annotation/
so there is created an extra table for each relation so for the example there is needed definition in each class:
class Class1 {
@OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
@JoinTable(name="class1_MatchSetType",joinColumns = @JoinColumn( name="c1_id"),inverseJoinColumns = @JoinColumn( name="ms_id"))
@OrderColumn(name = "ind")
private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
class Class2 {
@OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
@JoinTable(name="class2_MatchSetType",joinColumns = @JoinColumn( name="c2_id"),inverseJoinColumns = @JoinColumn( name="ms_id"))
@OrderColumn(name = "ind")
private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
class Class3 {
@OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
@JoinTable(name="class3_MatchSetType",joinColumns = @JoinColumn( name="c3_id"),inverseJoinColumns = @JoinColumn( name="ms_id"))
@OrderColumn(name = "ind")
private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
So at the end there are
3 tables for Class1,Class2,Class3
3 tables for relation Class1_MatchSetType,Class2_MatchSetType,Class3_MatchSetType
1 table with common type - MatchSetType
[Updated on: Wed, 16 May 2012 13:26] Report message to a moderator
|
|
|
Re: Texo: how to declare one-to-many relations for different parent types? [message #872700 is a reply to message #872619] |
Wed, 16 May 2012 16:17 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Olaf,
Yes, still I don't yet understand... the reason to have join tables is that you can have duplicates in the one-to-many.
Also there is less change of naming collisions. Why did the direct foreign key association not work? Did you get
collisions in the generated foreign key, I mean did class1/class2/class3 accidentally share the same join column? Btw,
are this containment associations?
Note that in the epackage ORM annotation there are 2 options to control the usage of join tables for containment as well
as non-containment association.
gr. Martiin
On 05/16/2012 03:25 PM, Olaf Burdziakowski wrote:
> The solution is according to this explanation:
> http://www.mkyong.com/hibernate/hibernate-one-to-many-relationship-example-annotation/
>
> so there is created an extra table for each relation so for the example there is needed definition in each class:
>
> class Class1 {
> @OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
> @JoinTable(name="class1_MatchSetType",joinColumns = @JoinColumn( name="c1_id"),inverseJoinColumns = @JoinColumn(
> name="ms_id"))
> @OrderColumn(name = "ind")
> private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
>
> class Class2 {
> @OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
> @JoinTable(name="class2_MatchSetType",joinColumns = @JoinColumn( name="c2_id"),inverseJoinColumns = @JoinColumn(
> name="ms_id"))
> @OrderColumn(name = "ind")
> private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
>
> class Class3 {
> @OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
> @JoinTable(name="class3_MatchSetType",joinColumns = @JoinColumn( name="c3_id"),inverseJoinColumns = @JoinColumn(
> name="ms_id"))
> @OrderColumn(name = "ind")
> private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
>
> So at the ent there are
> 3 tables for Class1,Class2,Class3
> 3 tables for relation Class1_MatchSetType,Class2_MatchSetType,Class3_MatchSetType
> 1 table with common type - MatchSetType
--
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: how to declare one-to-many relations for different parent types? [message #876559 is a reply to message #876428] |
Thu, 24 May 2012 20:39 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Olaf,
Okay, I am currently reworking this part of Texo. It will work in 2 modes:
- generate complete annotations with full db schema almost guaranteed unique and stable join column naming
- generate minimal annotations, so the ORM defaults apply
In both cases your issue will be solved, the first because each of the class1/2/3 will get a unique column, in the
latter because there won't be a joincolumn annotation generated.
Will be a few days, around the weekend before I publish a new build.
gr. Martin
On 05/24/2012 05:23 PM, Olaf Burdziakowski wrote:
> I understand the idea of separate columns. The point is that Texo generate such declaration:
>
> class1{
> @OneToMany(cascade = { CascadeType.ALL }, targetEntity = MatchSetType.class)
> @OrderColumn(name = "ind")
> @JoinColumns({ @JoinColumn() })
> private List<MatchSetType> matchSet = new ArrayList<MatchSetType>();
>
> and this donot cause seperate columns. In database there is only single column for all clases, but keys for many tables.
>
>
--
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
|
|
|
Goto Forum:
Current Time: Thu Sep 26 09:33:48 GMT 2024
Powered by FUDForum. Page generated in 0.04566 seconds
|