-->
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: bi-directional relationship problem... please help
PostPosted: Tue Feb 28, 2006 1:52 am 
Newbie

Joined: Tue Feb 28, 2006 1:37 am
Posts: 2
Hi Guys,
I'm trying to save an object (application) with a child object (appAfterMarketOption) through setting cascade="save-update"
I'm getting an error because when it tries to save the child object (after the parent has been saved), it's not updating the foreign key to the parent within the object.

org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not insert: [com.lp.ebus.common.pojo.AppAfterMarketOption]; SQL [insert into APP_AFTER_MARKET_OPTION (OPTION_NAME, OPTION_COST, OPTION_FITMENT_DATE, APPLICATION_ID, APP_AFTER_MARKET_OPTION_ID) values (?, ?, ?, ?, default)]; Assignment of a NULL value to a NOT NULL column "TBSPACEID=2, TABLEID=3, COLNO=4" is not allowed.; nested exception is com.ibm.db2.jcc.b.SQLException: TBSPACEID=2, TABLEID=3, COLNO=4
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:91)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:257)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:411)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:361)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:593)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at com.lp.ebus.common.host.dao.hibernate.ApplicationDAOHibernate.create(ApplicationDAOHibernate.java:105)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at com.lp.ebus.common.service.ApplicationManager.create(ApplicationManager.java:84)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at com.lp.ebus.nla.web.action.PrintAndAcceptanceAction.execute(PrintAndAcceptanceAction.java:61)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at com.ibm.wps.portlets.struts.WpsRequestProcessor.processActionPerform(WpsRequestProcessor.java:251)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at com.ibm.wps.portlets.struts.WpsStrutsPortlet.processActionPerformed(WpsStrutsPortlet.java:1536)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at com.ibm.wps.portlets.struts.WpsStrutsPortlet.actionPerformed(WpsStrutsPortlet.java:1254)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at com.ibm.wps.pe.pc.legacy.SPIPortletInterceptorImpl.handleEvents(SPIPortletInterceptorImpl.java:438)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.apache.jetspeed.portlet.Portlet._dispatch(Portlet.java:794)
[28/02/06 14:15:38:906 EST] 82beed4 SystemErr R at org.apache.jetspeed.portlet.Portlet.access$100(Portlet.java:88)

the field it's refering to is ApplicationId with in AppAfterMarketOption table.

i've played around with my mapping files a bit but can't see anything wrong.

within Application.hbm.xml
<!-- bi-directional one-to-many association to AppAfterMarketOption -->
<set
name="appAfterMarketOptions"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="APPLICATION_ID" />
</key>
<one-to-many
class="com.lp.ebus.common.pojo.AppAfterMarketOption"
/>
</set>


within AppAfterMarketOption.hbm.xml
<!-- bi-directional many-to-one association to Application -->
<many-to-one
name="application"
class="com.lp.ebus.common.pojo.Application"
not-null="true"
>
<column name="APPLICATION_ID" />
</many-to-one>


Any help would be greatly appreciated.... i'm completely stuck on this.

Thanks
David


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 6:32 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

1.

<set name="appAfterMarketOptions" inverse="true" cascade="all-delete-orphan" >
<key>
<column name="APPLICATION_ID" />
</key>
<one-to-many class="com.lp.ebus.common.pojo.AppAfterMarketOption" />
</set>

2. Make sure that:

child.setParent(parent);
parent.getChilds().add(child);
session.save(parent);

If it's still not working please post again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 6:37 pm 
Newbie

Joined: Tue Feb 28, 2006 1:37 am
Posts: 2
Thankyou so much for your help.. It's working now...

I think it must have been because i was just adding the child to the parent and not adding the parent to the child....

Thanks for your timely help, you've really saved my bacon here.
David


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.