We have a lot of objects with Composite keys of 3 elements. 2 of 3 elements (foreign key) are always immutable, this is guaranteed by our businesslogics. In the database unnecessary fields appear.
Code:
create table C
(
AID NUMBER(19) not null,
ID NUMBER(19) not null,
NAME VARCHAR2(255 CHAR),
B_AID NUMBER(19), --- unnecessary field !!!!!!!!!!!!!!!!!!!
B_ID NUMBER(19)
)
I tried @Joincolumns but I got the following exception:
org.hibernate.AnnotationException: referencedColumnNames(ID, A_ID) of
entities.C.b referencing entities.B not mapped to a single property.
What could I do to make the unnecessary fields disappear?
Code:
@Entity
public class A implements Serializable {
@Id
private Long id;
private String name;
}
@Entity
@IdClass(BId.class)
public class B implements Serializable {
@Id
Long id;
@Id
Long aid;
@ManyToOne
private A a;
private String name;
}
@Entity
@IdClass(BId.class)
public class C implements Serializable {
@Id
@Column(name="ID")
private Long id;
@Id
@Column(name="A_ID")
private Long aid;
@ManyToOne
@JoinColumns({
@JoinColumn(name="B_ID", referencedColumnName="ID"),
@JoinColumn(name="A_ID", referencedColumnName="A_ID")
})
private B b;
private String name;
}