0

I am converting an application from Grails to Java and need to find the equivalent of the inList constraints in grails to the spring/hibernate equivalent.

     static constraints = {
        stringValue(inList:['testValue', 'testValue', 'testValue', 'testValue', 'test value', 'test&value'], nullable:false)
   }

I am not sure what the hibernate/spring equivalent is for this type of constraint.

UPDATE

I tried using an enum but I need to include special characters such as & and spaces so to my knowledge only strings will work since I have to pull these values from a database.

Michael
  • 201
  • 2
  • 9
  • 1
    I don't think there is a built-in constraint, but you can write it yourself. Why don't you use an enum rather than a String? – JB Nizet Dec 25 '16 at 19:47
  • as said, an enum would do the job. or using a SET in Hibernate – RetteMich Dec 25 '16 at 19:58
  • I am going to set the variable to an enum as described in this answer http://stackoverflow.com/questions/3267520/declare-enum-variable-in-java-bean – Michael Dec 25 '16 at 21:29
  • Regarding your update, you should use an attribute converter to convert your enum to a string and vice-versa. Google for "JPA attribute converter" – JB Nizet Dec 29 '16 at 18:53

0 Answers0