-->
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: Hibernate saveOrUpdate not actually updating the DB
PostPosted: Sat Sep 23, 2006 2:25 am 
Newbie

Joined: Sat Sep 23, 2006 2:15 am
Posts: 3
I'm having some wierd behavior in which saveOrUpdate does not actually save my changes back to the database and no exceptions are thrown. Im not sure what exactly is going on. Here is my Hibernate Mapping file for the Object in question:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.tite.medicalworks.server.security.Role" table="roles">
<id name="ID" type="long" column="id">
<generator class="native"/>
</id>

<property name="name" type="string" unique="true"/>
<property name="description" type="string"/>

<map name="accessMatrix" table="role_category_access" inverse="false" order-by="category_id" cascade="all" lazy="false">
<key column="role_id"/>
<map-key column="category_id" type="int"/>
<element column="access_level" type="int"/>
</map>

</class>
</hibernate-mapping>

----------------------------------

I'm not sure what im doing wrong, but I call session.saveOrUpdate(someRole); and it doesn't update the DB. I resorted to making HQL calls for each field:

session.createQuery("update Role set name = '" + role.getName() + "' where id = " + role.getID()).executeUpdate();

session.createQuery("update Role set description = '" + role.getDescription() + "' where id = " + role.getID()).executeUpdate();

HOWEVER, when it came to the map in the Role object I tried to make sql calls to save the relationships and of course I reliazed executeUpdate for createSQLQuery was not supported. as it throw an exception. So Im not sure how to save back the mapping to the database at this point since hibernate refused to do it on its own. Its loads the roles fine, and saveOrUpdate works fine for other objects, im not sure why it doesn't for this particular class.

Any help would be much welcome!


Last edited by iudoka on Sat Sep 23, 2006 2:27 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 2:27 am 
Newbie

Joined: Sat Sep 23, 2006 2:15 am
Posts: 3
O yea, its very wierd because delete works, all mappings are removed so I'm not sure why saveOrUpdate is not working


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 11:26 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:09 am
Posts: 28
Hibernate tries to minimize DB access. Did you commit the hibernate transaction? Or call flush() on the session?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 1:40 pm 
Newbie

Joined: Sat Sep 23, 2006 2:15 am
Posts: 3
DC wrote:
Hibernate tries to minimize DB access. Did you commit the hibernate transaction? Or call flush() on the session?


Thanks for the response, yes I thought that might be the problem and I called flush with no success. The transaction is being managed by JBoss, so it should be committing the transaction. I am just perplexed because when I use HQL to save each field explicitly, it works.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 8:02 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
iudoka wrote:
DC wrote:
Hibernate tries to minimize DB access. Did you commit the hibernate transaction? Or call flush() on the session?


Thanks for the response, yes I thought that might be the problem and I called flush with no success. The transaction is being managed by JBoss, so it should be committing the transaction. I am just perplexed because when I use HQL to save each field explicitly, it works.


yes you have to commit transaction even in CMT env ...are you using slsb's ...how are you managing your transactions...???

_________________
Don't forget to rate


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.