[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] question about one-to-many
|
Hi,
I've an understanding problem using one-to-many:
I've got the following tables:
REZ_REZEPTE:
id: int
name: String
REZ_ZUT:
id: int
rezid: int
name: String
Now I want to have a List of all REZ_ZUT in REZ_REZEPTE.
This actually works:
@Entity
@Table { val name = "REZ_REZEPTE" }
@serializable
class Rezept {
@Id @GeneratedValue
@BeanProperty var id: Int = _id
@BeanProperty var name: String = _name
@OneToMany { val cascade = Array( CascadeType.ALL ), val targetEntity =
classOf[Zutat], val mappedBy = "rezept" }
@BeanProperty var zutaten: JList[Zutat] = null
}
But this needs class Zutat mapping back to 'Rezept'.
It should work to use
@OneToMany { val cascade = Array( CascadeType.ALL ), val targetEntity =
classOf[Zutat], val fetch=FetchType.EAGER }
@JoinColumn { val name = "rezid" }
@BeanProperty var zutaten: JList[Zutat] = null
but that give an error:
Internal Exception: Exception [EclipseLink-7160] (Eclipse Persistence Services -
1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.ValidationException
Exception Description: @OneToMany for attribute name [zutaten] in entity class
[class Rezept] should not have @JoinColumn(s) specified. In the case where the
@OneToMany is not mapped by another entity (that is, it is the owning side and
is uni-directional), it should specify (optional through defaulting) a @JoinTable.
I tried to use the xml-variant instead (which at least allows to define
join-columns):
<entity class="Rezept">
<attributes>
<id name="id"><generated-value /></id>
<one-to-many name="zutaten" target-entity="Zutat" fetch="EAGER">
<join-column name="rezid"/>
</one-to-many>
</attributes>
</entity>
But that gives a SQL-Exception - and I really don't know why EclipseLink is
trying to access a table named "rez_rezepte_rez_zut":
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build
20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table
'rez_rezepte_rez_zut' doesn't exist
Error Code: 1146
Call: SELECT t1.ID, t1.EINHEIT, t1.MENGE_MAX, t1.MENGE_MIN, t1.MENGE_ORG,
t1.NAME, t1.REZID FROM REZ_REZEPTE_REZ_ZUT t0, REZ_ZUT t1 WHERE ((t0.Rezept_ID =
?) AND (t1.ID = t0.zutaten_ID))
Can someone give me some insight where I'm going wrong?
Best regards, --- Jan.