File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes [Hibernate] Session.saveOrUpdate method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[Hibernate] Session.saveOrUpdate method" Watch "[Hibernate] Session.saveOrUpdate method" New topic
Author

[Hibernate] Session.saveOrUpdate method

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 509
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

Joined: Sep 12, 2008
Posts: 509
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

Joined: Mar 28, 2012
Posts: 859

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

Joined: Sep 12, 2008
Posts: 509
Spot on Bill I have verified that trigger gets executed by removing not-null = "true" from hbm.

Thank you.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Hibernate] Session.saveOrUpdate method