-->
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.  [ 4 posts ] 
Author Message
 Post subject: Exception is NOT thrown immediatelty! Why?
PostPosted: Wed May 03, 2006 5:10 am 
Newbie

Joined: Tue May 02, 2006 10:22 pm
Posts: 8
I am using Hibernate 3.

If I execute "session.update" and the update is not successful (e.g. value too large), the exception is not thrown immediately.

For example,

System.out.println ("pass 1");
session.update(dataBean) ;

System.out.println ("pass 2");
session.getTransaction().commit();

System.out.println ("pass 3");

I find if session.update(dataBean) fails, "pass 1" and "pass 2" are printed but "pass 3" is not printed. That meams Hibernate will not throw exception until I execute "commit". Can I force it to throw immediately (i.e. only "pass 1" will be printed) ?


Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 5:54 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
if your HQL/SQL/mapping-file is incorrect (e.g. wrong column names) then the error occurs when you trigger commit() to the database. Not before.

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 6:17 am 
Newbie

Joined: Tue May 02, 2006 10:22 pm
Posts: 8
so What can I do to make it throw immediately? Anything set in the config file?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 8:09 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Instead of session.commit(), you can invoke session.flush() which will throw exception if there is anything wrong.


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