-->
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.  [ 7 posts ] 
Author Message
 Post subject: Validation
PostPosted: Tue Apr 03, 2007 11:44 am 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
Hi,
All hibernate validation seems to happen during the commit. For example suppose I have the POJO:

Code:
public class Person {
    private String lastName;
   
   @Length(
        min = 0, max = 5, message = "Minimum {min}, maximum {max}   characters."
    )
    public String getLastName() {
         return lastName;
    }

    public void setLastName(String lastName) {
         this.lastName = lastName;
    }
}


and my application code is:

Code:
person.setLastName("123456789");


This is allowed, the exception is not thrown until commit is called.
I would have thought it would make more sense to throw an exception earlier?
Comments appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 7:27 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
But how do you want to do that ?
You would have to instrument your bit code or use AOP to intercept set call and verify constraints based on annotations when calling the setter.
This is not the case now. If you want to validate your object earlier, you can use ClassValidator.getInvalidValues(T)

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 4:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
JBoss Seam check the validity when the web form is received.
If you think about it, validations has to be triggered by something. And when the setter is used in not a good time

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 10:59 am 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
emmanuel wrote:
JBoss Seam check the validity when the web form is received.
If you think about it, validations has to be triggered by something. And when the setter is used in not a good time

Ok, thanks for that.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 6:46 am 
Beginner
Beginner

Joined: Sat Dec 09, 2006 12:02 pm
Posts: 26
Is here a solution right now? Maybe with an example?

I wanna generate my pojos with validating annotations ( e.g. @Length(
min = 0, max = 5, message = "Minimum {min}, maximum {max} characters."
) , and then i need to validate them...

Is there a tutorial or something else to implement this to my AbstractWizardFormController


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 1:37 am 
Beginner
Beginner

Joined: Wed Aug 24, 2005 5:32 am
Posts: 23
Hi,
I usually write frameworks for JEE application - so I trigger the validation
automatically using AOP interceptor somewhere between the application
service and the form. The code to invoke Hibernate validation is simple.
Here is an example:


Code:
      Item i = new Item();
      i.setPrice(3.3f);
      ClassValidator<Item> classValidator = new
            ClassValidator<Item>(Item.class);
      InvalidValue[] values = classValidator.getInvalidValues(i);
               
      for (InvalidValue value : values) {
                 System.out.println(value); //Will print the message
      }


I wrote about it on my blog, you can see it at:
http://www.jroller.com/page/eyallupu?entry=hibernate_validation_framework

I also explain on the blog some advanced Hibernate validator features - like how to write custom validators.

Eyal Lupu


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 06, 2007 5:40 pm 
Beginner
Beginner

Joined: Sat Dec 09, 2006 12:02 pm
Posts: 26
Hi eyall,

you wrote that you have annotated your properties with some rules.

Can you explain, how to generate all these rules on the properties? The properties are already generated with hibernate tools. is there a way to generate them with the annotations? (Withyout deleting the database... :-))

Dosi


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