-->
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: Validation constraint in @Embedded class
PostPosted: Mon Sep 14, 2009 7:40 am 
Regular
Regular

Joined: Tue Feb 17, 2009 5:13 am
Posts: 59
Hi all.

I need to validate the fields of an embedded-annotated class.

I have the following structure:

Code:
@Entity
@Table(name = "table_A", schema = "my_schema")
public class A implements Serializable {

   private B b = null;

   @Embedded
   public B getB() {
      return b;
   }

   public void setB(B b) {
      this.b = b;
   }
}

@Embeddable
public class B implements Serializable {

   private String field = null;

   @Column(name = "b_field")
   @Length(min = 5, max = 10)
   public String getField() {
      return field;
   }

   public void setField(String field) {
      this.field = field;
   }
}


When I create an A object with a B object with a 'field' field length less than 5 or greater than 10, validator does not detect the constraint violation... Example:

Code:
A a = new A();
B b = new B();
b.setField("");
//b.setField("string longer than 10 characters");
a.setB(b);


I know my validation configuration is right because if I try to validate other fields in A class, but not @Embeddable, it rights fine.
Is there any problem with @Embeddable fields validation?

_________________
Born to lose... live to win!


Top
 Profile  
 
 Post subject: Re: Validation constraint in @Embedded class
PostPosted: Wed Sep 16, 2009 8:58 am 
Hibernate Team
Hibernate Team

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

have you tried to add the @Valida annotation to getB(). You will have to tell validator that this object reference have to be validated as well.

--Hardy


Top
 Profile  
 
 Post subject: Re: Validation constraint in @Embedded class
PostPosted: Thu Sep 17, 2009 9:03 am 
Regular
Regular

Joined: Tue Feb 17, 2009 5:13 am
Posts: 59
Yes. I have annotated getter method with @Valid.

But it still failing.

Any idea?

_________________
Born to lose... live to win!


Top
 Profile  
 
 Post subject: Re: Validation constraint in @Embedded class
PostPosted: Mon Sep 21, 2009 12:28 pm 
Regular
Regular

Joined: Tue Feb 17, 2009 5:13 am
Posts: 59
Ummmm, I must be stupid...

I have tried it again, and now it works (with @Valid annotation). i don't know why the last time I tried it did not work... Perhaps I was drunked...

Thanks.

_________________
Born to lose... live to win!


Top
 Profile  
 
 Post subject: Re: Validation constraint in @Embedded class
PostPosted: Mon Sep 21, 2009 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Good to hear that it works now. I was about to ask for log messages, etc ;-)


Top
 Profile  
 
 Post subject: Re: Validation constraint in @Embedded class
PostPosted: Tue Jun 14, 2011 12:47 pm 
Newbie

Joined: Sun May 01, 2011 8:51 pm
Posts: 2
It doesn't get run from the JSF validation phase but only via JPA just before persist. Is there any way to get it to run via JPA validation?


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.