-->
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: Hibernate Validator and classes inheritance issue
PostPosted: Fri Aug 01, 2008 7:19 am 
Newbie

Joined: Fri Aug 01, 2008 6:29 am
Posts: 4
I have 2 classes in a hierarchy: Parent and Child. Parent has property i and it's getter. Child overrides this getter. I have annotated getters in both files with @Range annotation with different ranges. And I hope validator will take in use overriden annotation when persisting child( in my example I need range(1,10) to be used).
When validation performs on persisting it takes only parent's annotation, but not child's (i.e. range(3,6)).
And application crushes, because actual value is not in parent's range.

Is there any means to enforce Validator to use child's annotation instead of parent's? If not - maybe it's a bug?

Beforehand thank you for any help.


Hibernate Validator version: 3.0.0


Code:
@Entity
public class Parent {
   
   @Id
   @GeneratedValue
   private int id;
   
   private Integer i;
   
   public int getId() {
      return id;
   }
   
   public void setId(int id) {
      this.id = id;
   }
   
   @Range(min=3, max=6)
   public Integer getI() {
      return i;
   }

   public void setI(Integer i) {
      this.i = i;
   }
}



@Entity
public class Child extends Parent{
   
   @Range(min=1, max=10)
   public Integer getI() {
      return super.getI();
   }

}



Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 10:16 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The current behavior is to enforce all constraints (from parent and children). The Bean Validation spec will likely allow some kind of limited overriding.

_________________
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.