• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Hibernate] Session.saveOrUpdate method

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Database : Oracle


There is a trigger(before insert or update) that populates property1 and couple other fields. so obviously I am not setting those fields while preparing POJO. It executes the SELECT statement on the same table because this is saveOrUpdate() so it is understood. And for my test data that row is NOT going to exist so it is going to be INSERT query.

Question is, why does it throw NOT NULL exception when there is a trigger to populate those fields?
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting the same exception for Session.Save method too. Somehow the trigger is not getting executed while INSERT.

Is there any special treatment for trigger in hibernate? I do not have any reference of trigger in hibernate. I am assuming it is supposed to be execute at DB level so it does not need any reference in hibernate.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you set the not-null attribute using @Column annotation?

If so, your DB-only trigger will never get fired since Hibernate is validating your rules first.

Pat.
 
Saurabh Pillai
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spot on Bill I have verified that trigger gets executed by removing not-null = "true" from hbm.

Thank you.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic