-->
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.  [ 6 posts ] 
Author Message
 Post subject: Validator @NotNull and default nullability check
PostPosted: Tue Aug 19, 2008 4:24 am 
Newbie

Joined: Mon Mar 31, 2008 2:53 pm
Posts: 4
Hi All,

i'm a little confused by a 'quirky' thing that seems to happen. I've tried searching the forums but couldn't find the answer.

I'm Using Hibernate 3.2.6, Annotations 3.3.1 and Validator 3.0.0.

I'm annotating a few columns (on the property level) using @NotNull. When i call session.save/persist() with an instance of that entity it default nullability check kicks in before the validator does. So all i get is a single 'org.hibernate.PropertyValueException: not-null property references a null or transient value' exception. However i expected an InvalidStateException coming from the validator and having multiple InvalidValues (one for each NotNull that was violated).

I've tracked it down to the AbstractSaveEventListener that does the default nullability check (on line 290) (using org.hibernate.engine.Nullability) before doing an insert (on line 298) that triggers the Validator event.
The default nullability kicks in because the NotNull validator updates the metamodel of hibernate and sets the nullable attribute of the property to false.

Is there a 'right' way to work around this? It would only be a little work to code (well copy) your own NotNull validator and leave out the metamodel update, but it doesn't *feel* right that way (and that will cause the generated DDL to be wrong)

Any help will be appreciated...

Regards,
Robert


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 5:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

this is indeed an interesting problem. One way around it - provided you don't need the constraints reflected in the db - is to set the property hibernate.validator.apply_to_ddl to false. Alternatively, you can use @EntityListeners( JPAValidateListener.class ) instead of the hibernate event listeners. In this case you would have to set hibernate.validator.autoregister_listeners to false.

Check the online doc. All the described options and methods are described there.

It might be even worse to open a jira issue for this. One would expect that the validator kicks in first. I am not sure though if the order can easily be changed.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 5:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The problem is hard to solve, I need to sit down one day with Steve over this one.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 5:53 am 
Newbie

Joined: Mon Mar 31, 2008 2:53 pm
Posts: 4
Hi... thanks for the replies...

The easy option (the one i forgot) was to set hibernate.validator.apply_to_ddl to false. At the moment we are working with a custom @NotNull (and @NotEmpty) annotation implementation.

I'll try the entitylisteners when i get some time (you know project deadlines ;-)). Are the entitylisteners fired before the 'hibernate' event listeners?

Regards,
Robert


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 8:43 pm 
Newbie

Joined: Fri Mar 20, 2009 11:40 am
Posts: 4
emmanuel wrote:
The problem is hard to solve, I need to sit down one day with Steve over this one.


Is there anything new about this problem?


Top
 Profile  
 
 Post subject: Re: Validator @NotNull and default nullability check
PostPosted: Mon Oct 26, 2009 3:51 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 5:13 am
Posts: 59
Quote:
Is there anything new about this problem?


I'm afraid not...

I am having the same problem and I just upgrade my dependencies to the latest stable (hibernate-core 3.3.2, hibernate-annotations 3.4.0.GA and hibernate-validator 3.1.0.GA) and it still does not work.

hardy.ferentschik (Hibernate Team) told me to use a Hibernate 4.x based on Bean Validation, but there is no stable version yet.
(see viewtopic.php?f=9&t=998700)
So @NotNull validation still not working for null values... and I don't understand why!

_________________
Born to lose... live to win!


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