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.  [ 7 posts ] 
Author Message
 Post subject: Update Failure not throwing an Exception???
PostPosted: Fri Feb 10, 2006 11:37 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
Hi,


Hibernate version:

3.1


Mapping documents:

TimeStampUpdate.hbm.xml


<?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>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.sitx.common.certinventory.dto.TimeStampUpdateDTO" table="TIMESTAMPUPDATE">
<id name="timeid" type="string">
<column name="TIME_ID" length="10" />
<generator class="assigned" />
</id>
<timestamp name="upddate" column="UPT_DATE" unsaved-value="null" >
</timestamp>
<!--property name="upddate" type="timestamp">
<column name="UPT_DATE" length="7" />
</property-->
<property name="loginname" type="string">
<column name="LOGIN_NAME" length="15" />
</property>
</class>
</hibernate-mapping>





Code between sessionFactory.openSession() and session.close():

public void updateTimeStamp(Object obj) throws HibernateException{
Session hibSession = HibernateUtil.getSession();
HibernateUtil.beginTransaction();
if(obj!=null){
try{
hibSession.saveOrUpdate(obj);
}catch(HibernateException he){
he.printStackTrace();
}
}
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
}






Full stack trace of any exception that occurs:

No Exception (Where i am excepting an Exception)


Name and version of the database you are using:

Oracle 9i

The generated SQL (show_sql=true):

Hibernate: update TIMESTAMPUPDATE set UPT_DATE=?, LOGIN_NAME=? where TIME_ID=? and UPT_DATE=?

Debug level Hibernate log excerpt:


I am checking concurrency control thru timestamp. Checking whether
the timestamp data which i have got from DB is matching with the
timestamp data which u are going to set. If they are different,
Someone as modified the timestamp data in the db. So do a concurrency
check and dont allow the user to modify the timestamp data.
If the timestamp data's are same, no one has modified the code so allow the user to modify the timestamp data.
Where all these stuffs are happening fine. The only problem i have is
that if the table is not updated(becos,some one has modified the timestamp) it is printing the hibernate Update query has excepted.
But it is not throwing any exception, since no updation took place in the table. Where it is expected to throw a "HibernateException". So, that i can confirm to the user that some one has modified the timestamp data
already.

Why it is not throwing any exception, when no updation took place???
Is there we need to configure some where in hibernate.properties
or hibernate.cfg.xml for updation failure. So that it will throw the
exception has expected.

Please do provide a solution for this. Since this is so urgent...

Thanks,
HibernateCrazyLoverr


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 1:44 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
Is there any one there to help me out in this??


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 9:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You should expect the exception when the flush occurs. In the code snippet you posted, this would happen when the transaction commits.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 11:21 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
Hi Steve,

Thanks for your input. I have tried Session.flush(), still it is
not throwing any exception during the failure of updation.
I have also commented Session.commit(),but still there is no difference..
Can your provide any other solution to suggest where i am
actually going wrong...


Thanks,
HibernateCrazyLoverr


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 12:28 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
HibernateCrazyLoverr wrote:
Hi Steve,

Thanks for your input. I have tried Session.flush(), still it is
not throwing any exception during the failure of updation.
I have also commented Session.commit(),but still there is no difference..
Can your provide any other solution to suggest where i am
actually going wrong...


Thanks,
HibernateCrazyLoverr


Are you sure that your external database change is being committed before you try your update and that it is actually changing the timestamp of the record you're updating ?

I've never had a problem with using timestamps for optimistic locking.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 5:48 am 
Newbie

Joined: Wed Feb 01, 2006 12:45 pm
Posts: 18
We have also tried that by committing the transaction before updating the timestamp. But still it is giving the same problem where no exceptions
has been thrown.. where we are expecting a "StaleStateException".
Any suggestions regarding this are welcome..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 7:28 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
HibernateCrazyLoverr wrote:
We have also tried that by committing the transaction before updating the timestamp. But still it is giving the same problem where no exceptions
has been thrown.. where we are expecting a "StaleStateException".
Any suggestions regarding this are welcome..


I'm a little confused about the order of events. The only way that you'll get a StaleObjectStateStateException is if the following events occur.

1) Read Object in Hibernate code from database.

2) Update same row in database, including timestamp, externally and commit change to the database.

3) modify some data in the hibernate Object, but NOT the timestamp. Hibernate handles this for you.

4) commit change in hibernate - this should throw an exception.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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