Composite Primary Key
Composite primary keys means having more than one primary key, let us see few points on this concept.
Friend If the table has a primary key then in the hibernate mapping file we need to configure
that column by using <id /> element (remember this)
Even though the database table doesn’t have any primary key, we must configure one column as id (one primary key is must)
If the database table has more than one column as primary key then we call it as composite
primary key, so if the table has primary key of multiple columns , in order to configure these
primary key columns in the hibernate mapping file we need to use one new
element called <composite-id> …. </composite-id>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="javafiles.Creature" table="CREATURES_DATA">
<composite-id> <key-property name="id"/> <key-property name="name"/> </composite-id>
<property name="color" /> </class>
</hibernate-mapping>