Hibernate version: Hibernate 3.0.5, Hibernate Annotations Beta 2
Mapping documents:
@ManyToMany(targetEntity="x.y.z.entity.EntityType", cascade={CascadeType.PERSIST, CascadeType.MERGE})
@AssociationTable(table=@Table(name="ENTITY_TYPE_ADDRESS_TYPES",
uniqueConstraints={@UniqueConstraint(columnNames={"ADDRESS_TYPE_ID",
"ENTITY_TYPE_ID"},
primary=true)}),
joinColumns = {@JoinColumn(name="ADDRESS_TYPE_ID", nullable=false, unique=false)},
inverseJoinColumns = @JoinColumn(name="ENTITY_TYPE_ID", nullable=false, unique=false))
Debug level Hibernate log excerpt:
[DEBUG,SchemaExport,main] create table ENTITY_TYPE_ADDRESS_TYPES (
ADDRESS_TYPE_ID bigint not null,
ENTITY_TYPE_ID bigint not null
)
[DEBUG,SchemaExport,main] alter table ENTITY_TYPE_ADDRESS_TYPES
add constraint FK4410DC56C6953F
foreign key (ADDRESS_TYPE_ID)
references ADDRESS_TYPES
[DEBUG,SchemaExport,main] alter table ENTITY_TYPE_ADDRESS_TYPES
add constraint FK4410DC54E5D7242
foreign key (ENTITY_TYPE_ID)
references ENTITY_TYPES
I have defined a uni-directional many-to-many relationship using an association table. The table is created properly, but I don't seem to be able to find a way to specify that the association table should have a primary (or unique) key. I have tried adding several forms of the 'uniqueConstraints' tag (the latest is shown above) to the AssociationTable, but it is always ignored. I've tried it with a couple of different databases (HSQL and Derby), and it does the same thing in both.
Would someone point me in the right direction, please?
Thanks... Maury.
|