Table Structure:
Create Table primarytable (
Primarytableid int primary key,
Refkey varchar (16) -- associated key, note that it is not the ID
) Engine = InnoDB
Create Table childtable (
Childtableid int primary key,
Linkrefkey varchar (16) -- associate with the refkey in the primarytable table
) Engine = InnoDB
Hibernate ing file: (Note the red part)
Primarytable. HBM. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype hibernate-mapping public "-// hibernate/hibernate mapping DTD 3.0 // en"
Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd>
<Hibernate-mapping>
<Class
Name = "primarytable"
Table = "primarytable">
<ID name = "ID" type = "Java. Lang. Integer">
<Column name = "primarytableid"/>
<Generator class = "assigned"> </generator>
</ID>
<! -- The refkey attribute must be written; otherwise, Hibernate will say that this attribute cannot be found. -->
<Property name = "refkey" type = "Java. Lang. String">
<Column name = "refkey" length = "16"/>
</Property>
<Set name = "childtables" inverse = "true">
<! -- <Key column = "linkrefkey foreign key property" property-ref = "refkey"/> -->
<Key column = "linkrefkey" property-ref = "refkey"/>
<One-to-define class = "childtable"/>
</Set>
</Class>
</Hibernate-mapping>
Childtable. HBM. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype hibernate-mapping public "-// hibernate/hibernate mapping DTD 3.0 // en"
Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd>
<Hibernate-mapping>
<Class name = "childtable" table = "childtable">
<ID name = "ID" type = "Java. Lang. Integer">
<Column name = "childtableid"/>
<Generator class = "assigned"> </generator>
</ID>
<Property name = "linkrefkey" type = "Java. Lang. String">
<Column name = "linkrefkey" length = "16"/>
</Property>
</Class>
</Hibernate-mapping>
Http://topic.csdn.net/t/20060325/14/4639486.html