I am facing problem of how to map a composite primary key with foreign key
Tables are as:
* (p) --- Primary Key
1)
Product
------------
Product_id(p) int
login varchar2(20)
date_ins DATE
2)
Module
--------------
Module_id(p) int
Product_id(p) int
login varchar2(20)
date_ins DATE
3)
Site
---------
Site_id(p) int
login varchar2(20)
date_ins DATE
4)
Site_module_registration
--------------------------------
Site_id(p) int
Module_id(p) int
login varchar2(20)
date_ins DATE
My hibernate mappings are as follows:
<hibernate-mapping >
<class name="ModuleVO" table="MODULE">
<composite-id>
<key-property name="productId" column="PRODUCT_ID" />
<key-property name="moduleId" column="MODULE_ID" />
</composite-id>
<property name="whoIns" column="WHO_INS" />
<property name="moduleName" column="MODULE_NAME" />
</class>
<class name="ModuleInfoVO" table="Site_Module_Registration">
<composite-id>
<key-many-to-one name="siteVO" class="SiteVO" column="Site_ID"/>
<key-many-to-one name="moduleVO" class="ModuleVO" >
<column name="MODULE_ID" />
<column name="PRODUCT_ID" />
</key-many-to-one>
</composite-id>
<property name="whoIns" column="WHO_INS" />
</class>
<class name="PublishModuleVO" table="MODULE" >
<composite-id >
<key-property name="moduleId" column="MODULE_ID" />
<key-property name="productId" column="PRODUCT_ID" />
</composite-id>
<property name="whoIns" column="WHO_INS" />
</class>
</hibernate-mapping>
The class mapped to the table have the properties as follows( I have omitted the getter & setter methods)
1)
public class PublishModuleVO implements Serializable {
private String productId;
private String moduleId;
private String whoIns;
}
2)
public class ModuleVO {
private int productId;
private int moduleId;
private String moduleName;
private String whoIns;
private ProductVO productVO;
}
3)
public class ModuleInfoVO implements Serializable {
private SiteVO siteVO = null;
private ModuleVO moduleVO = null;
private String whoIns;
}
4)
public class SiteVO {
private int siteId;
private String whoIns;
}
Note: There are other properties in the classes which I have not shown.
According to the above mapping I have given Module_id & Product_id as composite primary key in the ModuleVO mapping.
It works fine even for PublishModuleVO mapping.
But when i try to fetch data using ModuleInfoVO it is giving error as:
Hibernate: select modulevo0_.PRODUCT_ID as PRODUCT1_, modulevo0_.MODULE_ID as MODULE2_,
modulevo0_.WHO_INS as WHO3_9_, modulevo0_.MODULE_NAME as MODULE4_9_
from MODULE modulevo0_ where modulevo0_.PRODUCT_ID=1
and (modulevo0_.MODULE_ID not in (select modulevo2_.MODULE_ID
from Site_Module_Registration moduleinfo1_, MODULE modulevo2_
where moduleinfo1_.MODULE_ID=modulevo2_.PRODUCT_ID and moduleinfo1_.PRODUCT_ID=modulevo2_.MODULE_ID))
14:18:26,598 WARN JDBCExceptionReporter: SQL Error: 904, SQLState: 42000
14:18:26,598 ERROR JDBCExceptionReporter: ORA-00904: "MODULEINFO1_"."PRODUCT_ID"
: invalid identifier
14:18:26,619 WARN RequestProcessor: Unhandled Exception thrown: class org.hiber
nate.exception.SQLGrammarException
According to this error -- I am not able to give a proper mapping for foreign key for the composite key of Module Table( ie Module_id & product_id )
Please tell me what changes I have to make to these mappings.
|