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.