-->
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.  [ 2 posts ] 
Author Message
 Post subject: PropertyValueException and Hibernate Validator
PostPosted: Thu Dec 08, 2005 1:05 pm 
Newbie

Joined: Wed Dec 07, 2005 2:01 pm
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]hibernate-annotations-3.1beta6[b]


I have annotated a method to take advantage of the Hibernate Validator.

Code:
    @Column(name = "ValueType", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
    @Length(max=20)
    @NotNull
    public String getValueType()
    {
        return this.valueType;
    }

    public void setValueType(String valueType)
    {
        this.valueType = valueType;
    }



If I set a non-null field to null, and do a save, I get a PropertyValueException instead of an InvalidStateException. The @Length constraint is throwing an InvalidStateException like expected. I removed "nullable = false" from the @Column annotation and still got the PropertyValueException.

Is this behavior correct? I was hoping to only have to catch InvalidStateExceptions for validation errors. I don't really see the point of even having the @NonNull constraint if the PropertyValueException is going to be thrown anyways.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 1:46 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The thing is the Validator check the entities that are going to be inserted/updated for real. Hibernate test the not-null at runtime before starting a insert/update action hence the mismatch.
At the end of the day, your entity is properly tested, but I don't see a good way to workaround this mismatch.

_________________
Emmanuel


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