This issue is encountered in the previous period, mainly the writing of HBM files. I built two tables. The PID in the PID and the CID in Child is a couple of relationships. The CID and OtherId in Child use primary key. As follows
PARENT table
Field name Type Length PID (PK) Character 10 Name Character 10
Child table
Field Name Type Length CID (PK) Character 10 OtherId (PK) Smallint
Name Character 10
HBM file:
Parent.hbm.xml
XML Version = "1.0" Encoding = "GB2312"?>
Id> set> class> hibernate-maping>
Child.hbm.xml
XML Version = "1.0" Encoding = "GB2312"?>
composite-id> class> hibernate-maping> These two HBM files are mainly: set> and child
These two constitute a two-way association of a combined primary key in a multi-relation. In addition to writing the PO class, pay attention to the correct written by Hashcode and Equals.