-->
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: Recursing @Valid with @Embeddable
PostPosted: Thu Oct 27, 2005 7:09 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
Doesn't seem to work. Sample scenario:

Code:
@Embeddable (access=AccessType.FIELD)
public class Contact
{
@NotNull
private String name ;
@NotNull
private String phone ;
...
}

@Entity (access=AccessType.FIELD)
{
@NotNull
private String city ;
@NotNull
private String state ;
...
}

@Entity (access=AccessType.FIELD)
public class Site
{
@NotNull
private String siteName ;

// validation recurses
@Valid
private Address address ;

// validation does not recurse
@Valid
private Contact contact ;
}

When validating "Site", the validator seems to ignore the @NotNull annotations on "Contact".

FWIW, I'm using SEAM, which is calling the hibernate validator for me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
OK, this is a bug, open it to JIRA saying,
use instance instead of class to avoid circular references in validator

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 2:48 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
Done.

http://opensource2.atlassian.com/projec ... se/ANN-137


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 1:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I cannot reproduce with your sample. I've got the right invalidvalues returned

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 5:44 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
hrm...

maybe specific to the version that i'm using... let me confirm.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 2:19 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
Got this to work. Stupid error on my part, the @NotNull field was actually being set to an empty String and the error wasn't caught on unit tests.

Sorry for the noise.


For those who care, it's probably good practice to always use @Length (min = 1) for varchar columns, especially if the column has a UNIQUE constraint.

Code:
// required column
@NotNull
@Length (min = 1, max = 100)
@Column (nullable = false, unique = true)
private String serialNumber ;

// non - required column
@Length (min = 1, max = 100)
@Column (nullable = true, unique = true)
private String licenseNumber ;


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.