Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Rollback transaction in hibernate  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
I've created Hibernate „create” method:



When some exception occurs (for example, unique constraint in DB), then catch block executes. After one error, I cant create another rows… I get exception about old error. For example, I create user „test”, then I trying add user with same name „test” and I’m getting hibernate error in log file. Then I’m trying to add new unique user, with new username „test2”, but still get old error about „test” user. Where is the problem?

So, real example:

I'm added testuser1@ttt.org, after that, I tryed add this user once more (and gets exception(below))... Now I'm trying to add user "testuser3@ttt.org" but I'm getting this error about testuser1@ttt.org again:



Thanks.
 
Andris Sigs
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas? Please help.
 
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you're interpreting the logs correctly? I don't see two identical error messages with different timestamp in your log.

If you're getting this result consistently, perhaps you could create a SSCCE?

By the way, catching Exception and returning null instead doesn't look good to me. I'd prefer to have an exception unwind through the application to the level where it can be handled (probably to the point where you're able to tell the user an error has happened). But I don't think this is the cause of your problems.
 
Andris Sigs
Greenhorn
Posts: 19
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, problem was in Session… After each error I must create new Session…
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's true. Thanks for sharing the solution!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!