Hi, I have two classes Person and Subject. There is a many-to-many relationship between them. The interesting thing is that Person uses
uuid-style id, NOT numbers. Here is the hibernate mapping file for Person:
<class name="Person" table="PERSON">
<id name="id" type="string">
<column name="ID" sql-type="CHAR(32)"/>
<generator class="uuid.hex"/>
</id>
<set name="subjects" table="PERSON_SUBJECT" cascade="all-delete-orphan" lazy="true">
<key column="PERSON_ID"/>
<many-to-many class="Subject" column="SUBJECT_ID"/>
</set>
</class>
The following mapping is for Subject:
<class name=Subject"
table="SUBJECT">
<id name="id" type="long" column="ID">
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="NAME" length="150"/>
</property>
</class>
When I use Hibernate to create database tables, I always get the following error message:
[hibernatetool] 10:00:17,125 ERROR SchemaExport:167 - Unsuccessful: alter table PERSON_SUBJECT add constraint FK225EBD9AF2EBA0FC foreign key (PERSON_ID) references PERSON
[hibernatetool] 10:00:17,125 ERROR SchemaExport:168 - Column 'PERSON.ID' is not the same data type as referencing column 'PERSON_SUBJECT.PERSON_ID' in foreign key 'FK225EBD9AF2EBA0FC'.
If I use number as Person's id, then there is no such problem.
Did I do something wrong? or Do I have to have special treatment for UUID-style IDs in associations?
Regards,
Pete
|