我有一个非常简单的项目,有 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;
}
将一个具有两个 BI 的 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
任何的想法?
谢谢!
问候。
塞达诺。