-->
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.  [ 5 posts ] 
Author Message
 Post subject: PropertyValueException in H4 to H5 migration
PostPosted: Wed Oct 19, 2016 4:43 am 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
I've been migrating the Hiberrnate version and I've found some issues.

I had some entities like:
@Basic(optional = false)
@Column(name = "discount_price", nullable = false, precision = 10, scale = 2)
private BigDecimal discountPrice;

But in my mysql BBDD can be NULL (not checked NN). This did not throw any exception and all was working Ok in Hibernate 4. But now with Hibernate 5 I think that this is more strict or some validation class has been added to the classpath and I get:
org.hibernate.PropertyValueException: not-null property references a null or transient value : .....model.entities.Product.discountPrice

Is there any way to avoid this validation?, I have many entities and I want to avoid to check all the fields.


Last edited by quark on Wed Oct 19, 2016 4:48 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: PropertyValueException in H4 to H5 migration
PostPosted: Wed Oct 19, 2016 4:48 am 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
I think that I 've found the answer:
<prop key="hibernate.check_nullability">false</prop>
And Hibernate documentation says:
Enable nullability checking. Raises an exception if a property marked as not-null is null.
Default to false if Bean Validation is present in the classpath and Hibernate Annotations is used, true otherwise.


And is strange because I've the maven dependency:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.2.Final</version>
</dependency>


Top
 Profile  
 
 Post subject: Re: PropertyValueException in H4 to H5 migration
PostPosted: Wed Oct 19, 2016 4:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You need to remove
Code:
@Basic(optional = false)
if the entity attribute is nullable.

The whole purpose of the
Code:
optional=false
attribute is to validate that the attribute is NOT NULL.


Top
 Profile  
 
 Post subject: Re: PropertyValueException in H4 to H5 migration
PostPosted: Wed Oct 19, 2016 4:55 am 
Newbie

Joined: Wed Oct 19, 2016 2:57 am
Posts: 13
vlad wrote:
You need to remove
Code:
@Basic(optional = false)
if the entity attribute is nullable.

The whole purpose of the
Code:
optional=false
attribute is to validate that the attribute is NOT NULL.


Yes, but there was no check in my Hibernate 4. There was this inconsistency and the no exception was thrown. So I guess that in H4 the check was false by default.

Thank you vlad.


Top
 Profile  
 
 Post subject: Re: PropertyValueException in H4 to H5 migration
PostPosted: Wed Oct 19, 2016 4:59 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The Hibernate 4 was misbehaving then.


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