Hi,
does hibernate support to map 2 equal Java fields used as FK in a compound key into the same database column?
Both fields being fetched, but only one being inserted.
Code:
// Three simple entities A, B, C
@Entity class A {
@Id String a;
}
@Entity class B {
@Id String b;
}
@Entity class C {
@Id String c;
}
// Two link tables A-B and A-C using compound keys
@Embeddable class AB_PK {
A a;
B b;
}
@Entity class AB {
@Id AB_PK abPk;
}
@Embeddable class AC_PK {
A a;
C c;
}
@Entity class AC {
@Id AC_PK acPk;
}
// So far so good. But now it comes to define a link table between AB and AC,
// where both 'a' columns are identical and exist only once in the database
@Embeddable class ABAC_PK {
AB ab;
AC ac;
}
@Entity class ABAC {
@Id ABAC_PK abacPk; // requires 4 columns a, b, a, c.
}
Is there any way to use the above defined ABAC_PK layout with a database table
which only contains a, b and c PK columns, but not column 'a' twice (with some other name).
In other words. Is there a way to map:
Code:
abacPk.ab.abPk.a.a
abacPk.ab.abPk.b.b
abacPk.ac.acPk.a.a // with same value as: abacPk.ab.abPk.a.a
abacPk.ac.acPk.c.c
into the three database columns a, b, c? Preferable via annotations.
I tried several @Column, @AttributeOverwrite combinations but wasn't able to manage this.
BTW: I know that I'm able to define ABAC_PK as:
Code:
@Embeddable class ABAC_PK {
AB ab;
String c;
}
Thanks,
Jürgen