-->
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: Override validation on subclass method
PostPosted: Mon May 24, 2010 1:05 pm 
Newbie

Joined: Mon May 24, 2010 12:50 pm
Posts: 1
Hi there

I am currently using Hibernate Validator 4.0.2.GA, to validate my entities.

My problem is that I have class Parent which superclasses Child. When getValue() is called on the Parent object I want to ensure that the value returned in not null. I override getValue() on Child class, with the intention that getValue() on this method is not subject to same validation as the parent class method (i.e. it can return null). Unfortunately even though I override the method in a subclass, it still seems to be subject the validation defined on the parent method I am overriding. Is there anyway to get around this, via configuration for example, or is this just the want the tool/language/specification works?

Example code here:

public class Parent {

protected String value;

@NotNull
public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}

public class Child extends Parent {

@Override
public String getValue() {
return value;
}
}

Any suggestions appreciated.

Thanks

Pat


Top
 Profile  
 
 Post subject: Re: Override validation on subclass method
PostPosted: Tue May 25, 2010 3:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
Unfortunately even though I override the method in a subclass, it still seems to be subject the validation defined on the parent method I am overriding.

That's correct. Constraints are per spec inherited from super to sub class. Also constraints placed on implemented interfaces are validated.

Quote:
Is there anyway to get around this, via configuration for example, or is this just the want the tool/language/specification works?

No, currently there is no such thing. This thread is relevant to your question - viewtopic.php?f=26&t=985463

If you think this feature should be included in the next version of the Bean Validation spec you can create an jira issue in BVAL and/or create a feature request in Hibernate Validator HV.

--Hardy


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.