-->
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.  [ 2 posts ] 
Author Message
 Post subject: composite foreign key
PostPosted: Tue Feb 13, 2007 11:27 pm 
Newbie

Joined: Tue Feb 13, 2007 10:57 pm
Posts: 2
HI, was hoping someone on this forum could help. My cust_part_svc table has a foreign key constraint on service_level and partner_id fields.

I have double checked my mapping, but after pojo code is generated, I get an error when trying to insert record into cust_part_srvc. The hibernate insert statement does not include service_level in argument list.

I don't understand why the service_level field is not being persisted to the database.


ALTER TABLE CUST_PART_SVC ADD (
CONSTRAINT FK_CPS_PSL
FOREIGN KEY (PARTNER_ID, SERVICE_LEVEL)
REFERENCES PARTNER_SVC_LVL (PARTNER_ID,SERVICE_LEVEL));


REVERSE ENGINEERING:
<hibernate-reverse-engineering>

<schema-selection match-schema="PART_SRV" match-table="CUST_PART_SVC"/>
<schema-selection match-schema="PART_SRV" match-table="PARTNER_SVC_LVL"/>

<table schema="PART_SRV" name="CUST_PART_SVC" class="com.t.w.data.CustomerPartnerService" >
<primary-key>
<key-column name="PARTNER_ID" type="int" property="partnerId"/>
<key-column name="CUSTOMER_ID" type="long" property="customerId"/>
</primary-key>
<column name="SERVICE_LEVEL" property="serviceLevel" type="int"/>
</table>

<table schema="PART_SRV" name="PARTNER_SVC_LVL" class="com.t.w.data.PartnerServiceLevel" >
<primary-key>
<key-column name="PARTNER_ID" type="int" property="partnerId"/>
<key-column name="SERVICE_LEVEL" type="int" property="serviceLevel"/>
</primary-key>
<column name="PRIORITY" property="priority" type="int"/>
</table>
</hibernate-reverse-engineering>


MAPPING FILE FOR CUSTOMERPARTNERSERVICE:
<hibernate-mapping>
<class name="com.t.w.data.CustomerPartnerService" table="CUST_PART_SVC" schema="PART_SRV">

<composite-id name="id" class="com.t.w.data.CustomerPartnerServiceId">
<meta attribute="use-in-tostring">true</meta>
<key-property name="partnerId" type="int">
<column name="PARTNER_ID" precision="22" scale="0" />
</key-property>
<key-property name="customerId" type="long">
<column name="CUSTOMER_ID" precision="20" scale="0" />
</key-property>
</composite-id>

<many-to-one name="partners" class="com.t.w.data.Partner" update="false" insert="false" fetch="select">
<column name="PARTNER_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="customer" class="com.t.w.data.Customer" update="false" insert="false" fetch="select">
<column name="CUSTOMER_ID" precision="20" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="partnerSvcLvl" class="com.t.w.data.PartnerServiceLevel" update="false" insert="false" fetch="select">
<column name="PARTNER_ID" precision="22" scale="0" not-null="true" />
<column name="SERVICE_LEVEL" precision="22" scale="0" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>

GENERATED CLASSES:
CustomerPartnerService
CustomerPartnerServiceId
PartnerServiceLevel
PartnerServiceLevelId


JAVA CODE:
public void createCustomerPartnerService(long customerId, int partnerId, int serviceLevel, String service) throws DataException {

CustomerPartnerServiceId id = new CustomerPartnerServiceId(partnerId, customerId);
CustomerPartnerService custPartService = new CustomerPartnerService(id);
custPartService.setPartnerSvcLvl(new PartnerServiceLevel(new PartnerServiceLevelId(partnerId,serviceLevel)));
custPartService.setAllServices(service);

try {
save(custPartService);
} catch (Exception e) {
throw new DataException(DataException.GENERAL_ERROR, e.toString());
}
}


EXCEPTION WHEN INSERTING INTO CUST_PART_SVC:
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update;
SQL [insert into PART_SRV.CUST_PART_SVC (MOD_USER, MOD_DTTM, CREATE_USER, CREATE_DTTM, ALL_SERVICES, PARTNER_ID, CUSTOMER_ID) values (?, ?, ?, ?, ?, ?, ?)];
ORA-02291: integrity constraint (PART_SRV.FK_CPS_PSL) violated - parent key not found


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 14, 2007 2:35 pm 
Newbie

Joined: Tue Feb 13, 2007 10:57 pm
Posts: 2
the re-up :]


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

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.