-->
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: executeUpdate() is being called before saveOrUpdate()
PostPosted: Tue Jul 31, 2012 1:41 pm 
Newbie

Joined: Tue Jul 31, 2012 1:26 pm
Posts: 1
Actually, I have one scenario where I need to insert master record and update already existed bunch of child records with new master record id.
For this I have called saveOrUpdate() to save master record and get the ID, which was generated and called executeUpdate() to update my bunch of records by update statement.

The problem is, first it executes my update statements, where it tried to update all child records with new parent key. As the new parent record was not inserted it throws db exception.

saveOrUpdate() is being called after my update statements.

How can I synchronize these two calls, so that I can insert my new parent record with saveOrUpdate() first and update my all child questions with executeUpdate(), which takes hql update statement.


Please provide your answers / resolutions if any one face this issue.

Attaching the code snippet for clear understanding


Transactional(propagation = Propagation.SUPPORTS, rollbackFor = SFFDatabaseException.class, isolation = Isolation.READ_UNCOMMITTED)
public Response editQuestion(parentRequest parentRequest)
throws SFFDatabaseException {
parent.setXXXX("XXXX");
parent.setXXXX("XXXX");
parent.setXXXX("XXXX");
sessionFactory.getCurrentSession().saveOrUpdate(parent);
parentId = parent.getId();
Query updateQuestion = sessionFactory.getCurrentSession().createQuery("update child set parentId=:nqid");
updateQuestion.setParameter("nqid", parentId);
updateQuestion.executeUpdate();

Here first it executes updateQuestion.executeUpdate(); then sionFactory.getCurrentSession().saveOrUpdate(parent); I am getting parent id in parentId but it is not saving the parent record first, so I am getting foreign key exception.

Thanks,
Vikram.N


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.