私は3つのクラスを持つ非常に単純なプロジェクトを持っています:
@Entity
@Table(name = "A", uniqueConstraints = {})
@org.hibernate.annotations.Table(appliesTo = "A", indexes = {})
@SecondaryTable(name = "C", pkJoinColumns {@PrimaryKeyJoinColumn(columnDefinition = "A_ID", name = "A_ID")})
public class Machine
{
@Id
@GeneratedValue
@Column(name = "A_ID", nullable = false)
private Integer id;
@Column(name = "a1", nullable = false)
private Integer a1;
@Column(name = "c1", table = "C", nullable = false)
private Integer c1;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "A_B", joinColumns = {@JoinColumn(name = "A_ID")}, inverseJoinColumns = {@JoinColumn(name = "B_ID")})
private List<B> bs = new ArrayList<B>();
}
@Entity
@Table(name = "B")
@SecondaryTable(name = "A_B", pkJoinColumns = {@PrimaryKeyJoinColumn(columnDefinition = "B_ID", name = "B_ID")})
@org.hibernate.annotations.Table(appliesTo = "B")
public class B {
@Id
@GeneratedValue
@Column(name = "B_ID", nullable = false)
private Integer id;
@Column(name = "B_1", nullable = false)
private Integer b1;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "d1", column = @Column(name = "D_1", table = "A_B")),
@AttributeOverride(name = "d2", column = @Column(name = "D_2", table = "datastore_assignment"))})
private final D d = new D();
}
@Embeddable
public class D
{
private long d1;
private long d2;
}
2 つの BI を持つ 1 つの A インスタンスをセッションに挿入すると、次のようになります。
A_B table
A_ID B_ID D_1 D_2
1 1 1 1
1 2 1 1
しかし、これは次のとおりです。
A_B table
A_ID B_ID D_1 D_2
1 1 0 0
1 2 0 0
1 NULL 1 1
1 NULL 1 1
何か案が?
ありがとうございました!
よろしく。
せだの。