I am creating a table with two primary keys. The first one is id(Integer) and second one is email(varchar2(50)).
My mapping file contains
<hibernate-mapping package="suri.sahasra">
<class name="Person" table="PERSONS">
<composite-id name="pkField" class="PKField">
<key-property name="personId" column="person_id"/>
<key-property name="email" column="email"/>
</composite-id>
<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name"/>
<property name="age" column="age"/>
</class>
</hibernate-mapping>
Now I am trying to select data using load method, but it’s raising a typeMisMatch Exception.
My load function is:
Person p1=(Person) ss.load(Person.class,new Integer("1"));
System.out.println(p1.getFirstName());
System.out.println(p1.getLastName());
System.out.println(p1.getAge());
How do you retrieve data if the table contains two primary keys. Please help me.
you have to use
and PKField must implement .equals() and hashcode() methods,
hibernate relies on these methods to cache and compare the data.