Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 87A3710805 for ; Mon, 27 Apr 2015 11:36:49 +0000 (UTC) Received: (qmail 66525 invoked by uid 500); 27 Apr 2015 11:36:49 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 66483 invoked by uid 500); 27 Apr 2015 11:36:49 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 66472 invoked by uid 99); 27 Apr 2015 11:36:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2015 11:36:49 +0000 X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests= X-Spam-Check-By: apache.org Received-SPF: error (athena.apache.org: local policy) Received: from [54.191.145.13] (HELO mx1-us-west.apache.org) (54.191.145.13) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2015 11:36:43 +0000 Received: from mail.inso.tuwien.ac.at (omega.inso.tuwien.ac.at [128.130.59.18]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id C9E4620659 for ; Mon, 27 Apr 2015 11:36:00 +0000 (UTC) Received: from [192.168.1.100] (77.119.131.222.wireless.dyn.drei.com [77.119.131.222]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.inso.tuwien.ac.at (Postfix) with ESMTPSA id 1EB76C46A7 for ; Mon, 27 Apr 2015 13:35:59 +0200 (CEST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Subject: Re: Mapping a Join Table with Additional Columns From: Mark Struberg In-Reply-To: <553D0AE0.8050901@debooy.eu> Date: Mon, 27 Apr 2015 13:35:58 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <553D0AE0.8050901@debooy.eu> To: users@openjpa.apache.org X-Mailer: Apple Mail (2.2098) X-Virus-Checked: Checked by ClamAV on apache.org Why don=E2=80=99t you use a @ManyToMany relation? LieGrue, strub > Am 26.04.2015 um 17:57 schrieb Marco de Booij = : >=20 > I use Tomee 1.7.1 with openjpa version = openjpa-2.4.0-nonfinal-1598334-r422266. >=20 > I have an entity auteurs and an entity boek. They have a ManyToMany = relation through the entity auteurs_boeken. In this entity there is a = field type to define the type of the relation (writer, illustrations, = ...). I followed the = https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany page and came = up with the following classes (left out all constructors, getters, and = setters): >=20 > =3D=3D=3D=3D=3D > @Entity > @Table(name=3D"AUTEURS", schema=3D"BYBLOS") > public class AuteurDto > extends Dto implements Comparable, Cloneable { > private static final long serialVersionUID =3D 1L; >=20 > @Id > @GeneratedValue(strategy=3DGenerationType.IDENTITY) > @Column(name=3D"AUTEUR_ID", nullable=3Dfalse, unique=3Dtrue) > private Long auteurId; > @Column(name=3D"NAAM", length=3D100, nullable=3Dfalse) > private String naam; > @Column(name=3D"VOORNAAM", length=3D100) > private String voornaam; >=20 > @OneToMany(cascade=3DCascadeType.ALL, fetch=3DFetchType.LAZY, = mappedBy=3D"auteur") > private List boeken; > } >=20 > =3D=3D=3D=3D=3D > @Entity > @Table(name=3D"BOEKEN", schema=3D"BYBLOS") > public class BoekDto extends Dto implements Comparable, = Cloneable { > private static final long serialVersionUID =3D 1L; >=20 > @Id > @GeneratedValue(strategy=3DGenerationType.IDENTITY) > @Column(name=3D"BOEK_ID", nullable=3Dfalse, unique=3Dtrue) > private Long boekId; > @Column(name=3D"DEEL", precision=3D5, scale=3D0) > private Integer deel; > @Column(name=3D"DRUK", precision=3D3, scale=3D0) > private Integer druk; > @Column(name=3D"ISBN", length=3D13) > private String isbn; > @Column(name=3D"JAAR_UITGAVE", precision=3D4, scale=3D0) > private Integer jaarUitgave; > @Column(name=3D"SUBDEEL", length=3D2) > private String subdeel; > @Column(name=3D"TAAL", length=3D2, nullable=3Dfalse) > private String taal; > @Column(name=3D"TITEL", length=3D100, nullable=3Dfalse) > private String titel; >=20 > @OneToOne(cascade=3DCascadeType.ALL, fetch=3DFetchType.LAZY) > @JoinColumn(name=3D"SERIE_ID", nullable=3Dfalse, updatable=3Dfalse) > private SerieDto serie; >=20 > @OneToMany(mappedBy=3D"boek", fetch=3DFetchType.LAZY) > private List auteurs; > } >=20 > =3D=3D=3D=3D=3D > @Entity > @Table(name=3D"AUTEURS_BOEKEN", schema=3D"BYBLOS") > @IdClass(AuteurBoekPK.class) > public class AuteurBoekDto > extends Dto implements Comparable, Cloneable { > private static final long serialVersionUID =3D 1L; >=20 > @Id > private Long auteurId; > @Id > private Long boekId; > @Column(name=3D"AUTEUR_TYPE", nullable=3Dfalse, length=3D1) > private String auteurType; >=20 > @ManyToOne > @PrimaryKeyJoinColumn(name=3D"AUTEUR_ID", = referencedColumnName=3D"auteurId") > private AuteurDto auteur; > @ManyToOne > @PrimaryKeyJoinColumn(name=3D"BOEK_ID", = referencedColumnName=3D"boekId") > private BoekDto boek; > } >=20 > When I fetch the boeken from within the AuteurDto I get the message: > = org.apache.openjpa.persistence.ArgumentException: = "eu.debooy.byblos.domain.AuteurBoekDto.auteur" defines a target of = "auteurId" for column "AUTEUR_ID", but that target does not exist in = table "BYBLOS.AUTEURS". > I have the same problem on the BoekDto. BoekDto has a OneToOne = relation with SerieDto and when I read the boeken from there I get the = correct boeken so I guess that the problem lies with my implementation = of the ManyToMany. Can someone show me the way to the correct = implementation? >=20 > Regards, >=20 > Marco