-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with Primary key & Foreign Key mapping
PostPosted: Wed Jul 13, 2005 5:40 am 
Newbie

Joined: Wed Jul 13, 2005 5:14 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.