Hi, I have created mapping files for the below two files. For the sake of simplicity, assume the table names and column names match their Java counterparts
class Prod{ Long id; Long wid; //In mapping file prmary key is id //Getters and Setters generated }
class Stage extends Prod{ //In mapping file composite key is (id, wid) //Empty class }
Here is the Hibernate Mapping file :
<?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="Prod" table="PROD" lazy="true"> <id name="id" column="id" type="java.lang.Long" unsaved-value="null"> <generator class="sequence"> <param name="sequence">HRCHY_NODE_SEQ</param> </generator> </id> </class> <class name="Stage" table="STAGE" lazy="true"> <composite-id> <key-property name="id" column="id" /> <key-property name="wid" column="wid" /> </composite-id> </hibernate-mapping>
I write a query : " from Prod prod where id = ?"; Hibernate generates a SQL query : select id, wid from STAGE (ID, WID) in ? Observe that in the generated SQL, the table is STAGE
Could anyone please help me as why this happens ?
|