I use SchemaExport to generate a mysql table called
userandrole. The table has an internalId, which is the PK. It also has a unique key (index) comprising
roleName and
userName. The interesting thing is that this unique key generated for the table ignores the specified key name (
key1). It uses the first column name of the composite key, ie,
roleName. I am not sure if this is intentional or just a small bug in SchemaExport.
Below is the Hibernate descriptor file.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.abcd.persist.UserAndRole"
table="userandrole"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="internalId"
column="internalId"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<property
name="roleName"
type="java.lang.String"
update="true"
insert="true">
<column name="roleName"
unique-key="key1"
length="200"
not-null="true"/>
</property>
<property
name="userName"
type="java.lang.String"
update="true"
insert="true">
<column name="userName"
unique-key="key1"
length="200"
not-null="true"/>
</property>
<property
name="creationDate"
type="java.util.Calendar"
update="true"
insert="true"
column="creationDate"
/>
</class>
</hibernate-mapping>