Hi all,
I have a wrong definition of the primary key for the table used to store the embedded components of an entity.
Hibernate: 3.5.1-Final
Code is:
Code:
@Entity(name = "A")
@org.hibernate.annotations.Entity(dynamicUpdate = true, optimisticLock = OptimisticLockType.VERSION)
@Table(name = "A")
public class ABean {
...
@ElementCollection(fetch = FetchType.EAGER, targetClass = AComponent.class)
@JoinTable(name = "B", joinColumns = @JoinColumn(name = "aid", nullable = false),
@UniqueConstraint(columnNames = {
ID, AComponent.OFFSET
})
)
@Sort(type = SortType.COMPARATOR, comparator = BComparator.class)
@ForeignKey(name = "FK_A_B")
public SortedSet<AComponent> getTemplates() {
return templates;
...
}
@Embeddable
public class AComponent {
...
@JoinColumn(name = "cid", referencedColumnName = "cid", nullable = false)
@ManyToOne(optional = false, targetEntity = CBean.class, fetch = FetchType.LAZY)
@ForeignKey(name = "FK_B_C")
public C getZone() {
return zone;
}
...
@Column(name = OFFSET, nullable = false)
@Index(name = "IDX_B_OFFSET")
public long getOffset() {
return offset;
}
...
}
The primary key created by hibernate is: 'aid', 'offset' and 'cid'.
I don't understand why 'cid' is a part of the pk. I suppose it is due to the @JoinColumn in the component but, in my opinion, it's a mistake or a bug.
Thanks.