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 B3F8217396 for ; Mon, 27 Apr 2015 18:27:22 +0000 (UTC) Received: (qmail 30439 invoked by uid 500); 27 Apr 2015 18:27:22 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 30400 invoked by uid 500); 27 Apr 2015 18:27:22 -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 30389 invoked by uid 99); 27 Apr 2015 18:27:22 -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 18:27:22 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: message received from 54.164.171.186 which is an MX secondary for users@openjpa.apache.org) Received: from [54.164.171.186] (HELO mx1-us-east.apache.org) (54.164.171.186) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2015 18:27:16 +0000 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id DCB6C43E3B for ; Mon, 27 Apr 2015 18:26:55 +0000 (UTC) Received: from mfilter42-d.gandi.net (mfilter42-d.gandi.net [217.70.178.172]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 17EC81720A3 for ; Mon, 27 Apr 2015 20:26:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter42-d.gandi.net Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter42-d.gandi.net (mfilter42-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id rB8WHEoI86C9 for ; Mon, 27 Apr 2015 20:26:47 +0200 (CEST) X-Originating-IP: 91.182.26.110 Received: from [172.16.2.104] (unknown [91.182.26.110]) (Authenticated sender: marco.mailbox@debooy.eu) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 883D0172089 for ; Mon, 27 Apr 2015 20:26:47 +0200 (CEST) Message-ID: <553E7F67.9050606@debooy.eu> Date: Mon, 27 Apr 2015 20:26:47 +0200 From: Marco de Booij User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: users@openjpa.apache.org Subject: Re: Mapping a Join Table with Additional Columns References: <553D0AE0.8050901@debooy.eu> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org The problem is that the join-table has a field (AUTEUR_TYPE) that I need=20 to fill. With the ManyToMany I do not have this possibility. Regards, Marco Op 27-04-15 om 13:35 schreef Mark Struberg: > Why don=E2=80=99t you use a @ManyToMany relation? > > LieGrue, > strub > > >> Am 26.04.2015 um 17:57 schrieb Marco de Booij : >> >> I use Tomee 1.7.1 with openjpa version openjpa-2.4.0-nonfinal-1598334-= r422266. >> >> I have an entity auteurs and an entity boek. They have a ManyToMany re= lation 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 pa= ge and came up with the following classes (left out all constructors, get= ters, and setters): >> >> =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; >> >> @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; >> >> @OneToMany(cascade=3DCascadeType.ALL, fetch=3DFetchType.LAZY, mapped= By=3D"auteur") >> private List boeken; >> } >> >> =3D=3D=3D=3D=3D >> @Entity >> @Table(name=3D"BOEKEN", schema=3D"BYBLOS") >> public class BoekDto extends Dto implements Comparable, Clone= able { >> private static final long serialVersionUID =3D 1L; >> >> @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; >> >> @OneToOne(cascade=3DCascadeType.ALL, fetch=3DFetchType.LAZY) >> @JoinColumn(name=3D"SERIE_ID", nullable=3Dfalse, updatable=3Dfalse) >> private SerieDto serie; >> >> @OneToMany(mappedBy=3D"boek", fetch=3DFetchType.LAZY) >> private List auteurs; >> } >> >> =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; >> >> @Id >> private Long auteurId; >> @Id >> private Long boekId; >> @Column(name=3D"AUTEUR_TYPE", nullable=3Dfalse, length=3D1) >> private String auteurType; >> >> @ManyToOne >> @PrimaryKeyJoinColumn(name=3D"AUTEUR_ID", referencedColumnName=3D"au= teurId") >> private AuteurDto auteur; >> @ManyToOne >> @PrimaryKeyJoinColumn(name=3D"BOEK_ID", referencedColumnName=3D"boek= Id") >> private BoekDto boek; >> } >> >> When I fetch the boeken from within the AuteurDto I get the message: >> org.= apache.openjpa.persistence.ArgumentException: "eu.debooy.byblos.domain.Au= teurBoekDto.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 relatio= n with SerieDto and when I read the boeken from there I get the correct b= oeken so I guess that the problem lies with my implementation of the Many= ToMany. Can someone show me the way to the correct implementation? >> >> Regards, >> >> Marco >