openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marco de Booij <>
Subject Mapping a Join Table with Additional Columns
Date Sun, 26 Apr 2015 15:57:20 GMT
I use Tomee 1.7.1 with openjpa version 

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 page and came 
up with the following classes (left out all constructors, getters, and 

@Table(name="AUTEURS", schema="BYBLOS")
public class AuteurDto
     extends Dto implements Comparable<AuteurDto>, Cloneable {
   private static final  long  serialVersionUID  = 1L;

   @Column(name="AUTEUR_ID", nullable=false, unique=true)
   private Long    auteurId;
   @Column(name="NAAM", length=100, nullable=false)
   private String  naam;
   @Column(name="VOORNAAM", length=100)
   private String  voornaam;

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, 
   private List<AuteurBoekDto> boeken;

@Table(name="BOEKEN", schema="BYBLOS")
public class BoekDto extends Dto implements Comparable<BoekDto>, Cloneable {
   private static final  long  serialVersionUID  = 1L;

   @Column(name="BOEK_ID", nullable=false, unique=true)
   private Long    boekId;
   @Column(name="DEEL", precision=5, scale=0)
   private Integer deel;
   @Column(name="DRUK", precision=3, scale=0)
   private Integer druk;
   @Column(name="ISBN", length=13)
   private String  isbn;
   @Column(name="JAAR_UITGAVE", precision=4, scale=0)
   private Integer jaarUitgave;
   @Column(name="SUBDEEL", length=2)
   private String  subdeel;
   @Column(name="TAAL", length=2, nullable=false)
   private String  taal;
   @Column(name="TITEL", length=100, nullable=false)
   private String  titel;

   @OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
   @JoinColumn(name="SERIE_ID", nullable=false, updatable=false)
   private SerieDto  serie;

   @OneToMany(mappedBy="boek", fetch=FetchType.LAZY)
   private List<AuteurBoekDto> auteurs;

@Table(name="AUTEURS_BOEKEN", schema="BYBLOS")
public class AuteurBoekDto
     extends Dto implements Comparable<AuteurBoekDto>, Cloneable {
   private static final  long  serialVersionUID  = 1L;

   private Long    auteurId;
   private Long    boekId;
   @Column(name="AUTEUR_TYPE", nullable=false, length=1)
   private String  auteurType;

   @PrimaryKeyJoinColumn(name="AUTEUR_ID", referencedColumnName="auteurId")
   private AuteurDto auteur;
   @PrimaryKeyJoinColumn(name="BOEK_ID", referencedColumnName="boekId")
   private BoekDto   boek;

When I fetch the boeken from within the AuteurDto I get the message:
<openjpa-2.4.0-nonfinal-1598334-r422266:1599166 fatal user error> 
"eu.debooy.byblos.domain.AuteurBoekDto.auteur" defines a target of 
"auteurId" for column "AUTEUR_ID", but that target does not exist in 
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?



View raw message