Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Problem mapping many-to-many relationship
Problem mapping many-to-many relationship [message #604743] Sat, 14 April 2007 17:27
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
Hi!


i have a little question which i had trouble answering; i would really
appreciate if someone could help me straighten it out. here it goes:

in short, im trying to create a two sided many-to-many relationship. i
have two classes, with two collections pointing to each other. i took my
mapping from here (http://www.elver.org/hibernate/ejb3_examples.html).
this is a pseudo ecore model with annotations:

-----------------------------------------------------

Class A:
|
|---> property collection AtoB
|
|---> Annotation:
@ManyToMany(fetch=LAZY cascade=NONE targetEntity="B" indexed="false")
@JoinTable(name="AandB")


Class B:
|
|---> property collection BtoA
|
|---> Annotation:
@ManyToMany(fetch=LAZY cascade=ALL targetEntity="A" mappedBy="AtoB"
indexed="false")
@JoinTable(name="AandB")

-----------------------------------------------------

from this ecore model, i get the following pseudo mapping file:

-----------------------

<class name="AImpl" entity-name="A" abstract="false" lazy="false"
discriminator-value="A" table="`A`">
<cache usage="read-write"/>
<id name="id" type="java.lang.Integer">
<column not-null="false" unique="false" name="`id`"/>
<generator class="identity"/>
</id>
<bag name="AtoB" lazy="true" table="`AandB`">
<key/>
<many-to-many entity-name="B" unique="false"/>
</bag>
</class>

<class name="BImpl" entity-name="Transmitter" abstract="false"
lazy="false" discriminator-value="B" table="`B`">
<cache usage="read-write"/>
<id name="id" type="java.lang.Integer">
<column not-null="false" unique="false" name="`id`"/>
<generator class="identity"/>
</id>
<bag name="BtoA" lazy="true" cascade="all" inverse="true" table="`AandB`">
<key/>
<many-to-many entity-name="A" unique="false"/>
</bag>
</class>

-----------------------

now, i notice that there is a <key/> tag with no column on it. is this
normal? and if not( which i suppose), how can i get it to set the column
key. also, how can i set a column in the many-to-many tag to produce
something like this: http://www.xylax.net/hibernate/manytomany.html

in the database, the join table that is created does not have any FK
columns; which obviously creates a runtime error. all it has is two
columns: "id" and "elt" (i dreally dont know where this elt comes from)


how can i properly setup the many-to-many relationship? could it be
that i must use joinColumn or some other annotation? and if so, how must
i use it?


thanks very much for your help!

best regards,
Previous Topic:[Teneo] Blank hibernate.hbm.xml?
Next Topic:Problem mapping many-to-many relationship
Goto Forum:
  


Current Time: Sat Oct 24 01:38:41 GMT 2020

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

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

Back to the top