Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Transaction failure crashes program

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a simple code and my insert fails due to not null but my program crashes. Even though insert call is in try catch block

At end of transaction ,it tries to commit transaction and my program crashes.

Is there any way, I can stop my program from crashing :-(

Any help is appreciated.


Service class



DAO class



Bean code



ApplicationContext




Exception Log is

 
Ali Shair
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has no one ever faced this issue. It is a very common scenario.

If you are trying to insert 3 records and 2nd one fail then hibernate does not insert 1 and 3 because they are in same transaction.

How could I get it done ? I still want to insert 1st and 3rd record even if 2nd one does fail.



 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The message suggests you are trying to insert a null value in a field that cannot be null. The field is name - check the value you are adding.


If you are trying to insert 3 records and 2nd one fail then hibernate does not insert 1 and 3 because they are in same transaction.

How could I get it done ? I still want to insert 1st and 3rd record even if 2nd one does fail.


This is transactions behaving as they are designed to. If the three inerts statements are not dependent on each other don't put them in the same transaction.
 
Create symphonies in seed and soil. For this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic