0

Using Spring Framework JPA I have an Entity

@Entity
@IdClass(ComposityKey.class)
@Table(name="table1")
public class Table1 {
    @Id
    @Column(name="tableId)
    private int tableId;

    @Id
    private int tableId2;
    ...
}

2nd Entity contains a reference to Table1

@Entity
@Table(name = "table2")
public class Table2 {

    @ManyToOne
    @JoinColumn(name="tableId")
    private Table1 table1;
}

Now I'm getting the obvious AnnotationException

A Foreign key refering Table1 from Table2 has the wrong number of column. should be 2

Table2 doesn't have tableId2 as a value

So how can i JoinColumn on a Composite Key?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
royB
  • 12,779
  • 15
  • 58
  • 80
  • Possible duplicate of [JPA @JoinTable - Three ID Columns](http://stackoverflow.com/questions/14899736/jpa-jointable-three-id-columns) – Olivier Grégoire Oct 18 '16 at 12:37
  • Not sure It's duplicate, Not same Exception. Also notice that i am missing one of the id's in the second column - How will I be able to use EmbededId without the data? – royB Oct 18 '16 at 12:47

0 Answers0