-->
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.  [ 5 posts ] 
Author Message
 Post subject: Many-to-one delete problem
PostPosted: Tue Nov 07, 2006 5:52 pm 
Newbie

Joined: Tue Sep 12, 2006 6:06 pm
Posts: 15
I'm having problems with a many-to-one relationship. I have an organization object that is associated with many resources. The association is bidirectional. Here is the mapping:

Organization:
Code:
   /**
    * @hibernate.set lazy="false"
    *       cascade="none"
    *      table="resource"
    *      inverse="true"
    *
    * @hibernate.collection-key column="organization_key"
    *
    * @hibernate.collection-one-to-many class="xxxx.domain.Resource"
    */
   public Set getResources() {


Resource:
Code:
   /**
    * @hibernate.many-to-one column="organization_key" not-null="false"
    *                        access="field"
    */
   public Organization getOrganization() {


Save/update seems to work correctly. The resource table's organization_key column is populated correctly. However, I am encountering a problem when I try to delete the resource. My delete code is as follows:

Code:
   public void delete(Resource resource) {
       getHibernateTemplate().delete(resource);
       getHibernateTemplate().flush();
   }


This yields the following error when executing the flush():
Code:
2006-11-07 15:24:10,750 [main] WARN  org.hibernate.util.JDBCExceptionReporter  - SQL Error: 0, SQLState: 01004
2006-11-07 15:24:10,750 [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Data truncation: Column set to default value; NULL supplied to NOT NULL column 'organization_key' at row 1
2006-11-07 15:24:10,750 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener  - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:138)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
   at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:815)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
   at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:813)
   at com.silversky.scheduler.dao.organization.AbstractOrganizationDaoImpl.flush(AbstractOrganizationDaoImpl.java:87)
   at com.silversky.scheduler.dao.organization.AbstractOrganizationDaoImpl.delete(AbstractOrganizationDaoImpl.java:82)


Any ideas on the cause of this error?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 9:01 pm 
Beginner
Beginner

Joined: Tue May 08, 2007 1:20 pm
Posts: 24
I have a similar problem in deleting associated objects.
Also in case of update Paretn object is updated but associated object is inserted

Could you please share your solution


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 10:50 pm 
Newbie

Joined: Tue Dec 05, 2006 7:40 am
Posts: 14
bansilal wrote:
I have a similar problem in deleting associated objects.
Also in case of update Paretn object is updated but associated object is inserted

Could you please share your solution

Hi,

You could give more information ? then could trying help you.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 09, 2007 11:56 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
On getResources, try cascade="delete-orphan".

Oh and do organization.getResources().remove(resource); before flushing.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Last edited by himawan on Sat Jun 09, 2007 12:22 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 09, 2007 11:58 am 
Beginner
Beginner

Joined: Tue May 08, 2007 1:20 pm
Posts: 24
Hi ualex
Thanks for your willingness to help. I highly appreciate it.
I have posted detail information on Hibernate forums. Here is the link
http://forum.hibernate.org/viewtopic.ph ... one+delete

To save your time please see just the last posting by me on Fri Jun 08, 2007 10:53 pm. It has info on problems with update/delete

Regards
Bansi


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