-->
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.  [ 3 posts ] 
Author Message
 Post subject: Validate superclass property in subclass (XML)
PostPosted: Wed Feb 22, 2012 11:27 am 
Newbie

Joined: Mon May 10, 2010 3:50 am
Posts: 3
Hi,

There have been already quite some topics about this, except how to use this in XML. (Please don't start the why XML discussion here :-) )
Code:
<bean class="com.SubObject">
   <field name="superField">
       <constraint annotation="org.hibernate.validator.constraints.NotBlank">
           <message>Should not be empty</message>
           <groups>
               <value>com.SomeGroup</value>
           </groups>
       </constraint>
    </field>
</bean>


Code:
public class SubObject extends SuperObject{

     public SubObject() {
         super();
     }

     private String someSubField;

     .. getters setters etc
}

public class SuperObject {

     public SuperObject() {
         super();
     }

     private String superField;

     .. getters setters etc
}


Now the error:

javax.validation.ValidationException: com.SubObject does not contain the fieldType superField


Top
 Profile  
 
 Post subject: Re: Validate superclass property in subclass (XML)
PostPosted: Thu Feb 23, 2012 3:10 pm 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Since the type "SubObject" doesn't contain a field "superField" you can't add a constraint to it. Instead you could override the getter for the field in the sub-class and add the constraint to that getter via XML.

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Validate superclass property in subclass (XML)
PostPosted: Mon Feb 27, 2012 8:20 am 
Newbie

Joined: Mon May 10, 2010 3:50 am
Posts: 3
Gunnar wrote:
Since the type "SubObject" doesn't contain a field "superField" you can't add a constraint to it. Instead you could override the getter for the field in the sub-class and add the constraint to that getter via XML.


That doesn't work, via reflection it's actually looking for the class attribute instead of using the getters and setters.


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