Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Is there a way to set up 'standoff' validations?
PostPosted: Wed Dec 23, 2015 3:35 pm 
Newbie

Joined: Wed Dec 23, 2015 3:33 pm
Posts: 2
Is there a way to separate a class from its validation annotations? If I have a public API and I'd rather not introduce a dependency on the annotation classes, can I keep the data somewhere else?


Top
 Profile  
 
 Post subject: Re: Is there a way to set up 'standoff' validations?
PostPosted: Thu Dec 24, 2015 5:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1530
You can separate the validation rules to XML:

https://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/chapter-xml-configuration.html

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Is there a way to set up 'standoff' validations?
PostPosted: Mon Jan 04, 2016 7:35 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Hi,

You can use XML as outlined by Vlad (or, the API for programmatic constraint declaration in Hibernate Validator).

I'd be interested in your rationale for avoiding that dependency, though. If you constrain your public API types, the constraints are part of the API, the user needs to adhere to these constraints (or they provide some form of guarantee to him, if e.g. constraining method return values). So IMHO it makes sense to expose the constraint information to API users as well (that's also the reason why all the Bean Validation constraint annotation types are meta-annotated with @Documented, which will cause them to be listed in JavaDocs of annotated elements). So it'd be interesting to learn more about your use case.

Btw. annotated classes can be loaded also if the annotation types are not present at runtime, so your API should still be usable also without the constraint annotation types (of course validation will not work then).

Cheers,

--Gunnar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.