-->
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: Session object updates not working after doing HQL update
PostPosted: Thu Nov 18, 2010 3:32 pm 
Newbie

Joined: Fri Mar 19, 2010 7:00 pm
Posts: 14
Ok I'm not very well versed when it comes to Hibernate so I will try to explain my problem. So I get an object by its ID from a DB table (table1). It's loaded fine. This objects has another object associated to it from another row in a different DB table (table2).

Once I have this object (object1) I can get the object associated to it with object1->getObject2().

I make changes (I'm 'deleting' this object but in reality just setting a deletedAt field to a date) to object1 and then have the DAO.save(object1). This works fine if I DON'T do what I'm going to describe next.

So the update above also sets object2 to deletedAt = some date (it also deletes object2). I need to UNDELETE this object and so I use HQL (is this HQL?):

Code:
String sql = "UPDATE table2 SET "
        + "deleted_at = :deleted_at "
        + "WHERE id = :id";

Query sqlQuery = session.createSQLQuery(sql);
logger.info("SQL QUERY : " + sql);
sqlQuery.setLong("id", id);
sqlQuery.setParameter("deleted_at", null, org.hibernate.Hibernate.DATE);
sqlQuery.executeUpdate();


If I include the method that runs this code then the original process I discussed above does NOT work! There are no exceptions. No errors. Just the DB rows (object1) i wanted to update are not updated.

Can anyone explain what's going on? Maybe you can't update objects in SEssion with HQL like I'm doing? I have tried 'evicting' both object1 and object2 with no success...

Thank you.


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.