-->
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.  [ 3 posts ] 
Author Message
 Post subject: Exception in <set>’s <one-to-many> unidirectio
PostPosted: Tue Jan 10, 2006 7:57 am 
Newbie

Joined: Wed Nov 23, 2005 7:29 am
Posts: 7
Exception in <set>’s <one-to-many> unidirectional mapping

Parent class mapping
====================
<id name="Id" column="ID"/>
<component name="childcomponent" >
<set name="value" lazy="false" cascade="save-update" >
<key column="parent_id" not-null="true" />
<one-to-many class="Child" not-found="ignore" entity-name="childentityname" />
</set>
</component>

...
</class>

Child class mapping
===================
<class name="Child" table="ChildTable" entity-name=" childentityname">

<composite-id name="childId" >
<key-property name="value" column=" childId" />
</composite-id>

<property name="parentid" column=" parentid" insert="false" update="false"/>

...
</class>

Parent table structure
======================
Id number (pk)
Parent_name varchar2(50);
Other cols….



Child table structure
=====================
Childid number (pk)
Parented number (fk to Parent table)
Other cols….

Database
========
DB2


Hibernate
=========
Version 3.0


When I tried to save the parent object(insert), Hibernate is trying to update the child table by preparing an Update statement. My requirement is to save all the Child objects present in set by preparing insert statements.

Can any body suggest me how to map the Child object correctly?

Throwing an exception by stack trace as follows.

org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not insert collection: [com.mci.etms.eb.dataobjects.EbTicket.com.mci.etms.eb.dataobjects.EbTicket.ALocationAccessHours.value#1997]; DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC: XWEEKMK1;0000000201; nested exception is com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC: XWEEKMK1;0000000201
com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC: XWEEKMK1;0000000201


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 8:04 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You should post the code you used to instanciante and save your objects.

Why do you use a composite-id for your Child.
<id name="value" column"xy" >
<generator="assigened"
...
should be fine.

I am not sure if the problem is coming from the composite-id. I have not tested so far how hibernate works with null values or "defined" valued in the composite-id.

Regards
Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 9:37 am 
Newbie

Joined: Wed Nov 23, 2005 7:29 am
Posts: 7
I am using composite-id because the key field is in a component class.

the follwing code shows how the parent is created.
===============================

ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
new String[] { "applicationContext-eb.xml" });
sessionFactory = (SessionFactory)appContext.getBean("DB2SessionFactory");
ebDBLayer = (EbDBLayer)appContext.getBean("ebDBLayer");
transactionManager = (PlatformTransactionManager)appContext
.getBean("transactionManager");

Instantiating the parent and filling it with data.

ebDBLayer.insert(parent);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.