Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Justin,</p> <p>I've been working with Hibernate Validator for the last couple of months. While I have not run into the same issue that you've described, I also have not extended <code>ClassValidator</code>. For custom validation, the <a href="http://docs.jboss.org/hibernate/stable/validator/reference/en/html/validator-defineconstraints.html#validator-defineconstraints-own" rel="nofollow noreferrer">Hibernate Reference Guide</a> indicates that writing custom constraints is the way to go. </p> <p>I have been able to use the built-in constraints almost exclusively on my current project. In one case, where I needed to do some very specific calculations on an integer field, I wrote a custom constraint as described in the reference guide; it was a breeze.</p> <p>Speaking to your specific problem, I wrote a simple test app as a sort of sanity check on my part:</p> <pre><code>import org.hibernate.validator.*; public class HibernateValidatorTest { @NotEmpty @NotNull private String validateMe; public static void main ( String[] args ) { ClassValidator&lt;HibernateValidatorTest&gt; validator = new ClassValidator&lt;HibernateValidatorTest&gt;( HibernateValidatorTest.class ); InvalidValue[] inVals = validator.getInvalidValues( new HibernateValidatorTest() ); for ( InvalidValue inVal : inVals ) { System.out.println( inVal.getMessage() ); } } } </code></pre> <p>With both Hibernate constraints on the <code>validateMe</code> field, the console output is:</p> <pre><code>may not be null or empty may not be null </code></pre> <p>Removing one or the other has the expected effect of printing only a single message to the console.</p> <p>I hope this is helpful.</p> <p>Brian T. Grant</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload