0

I'm getting following exepction when trying to import constraints from domain class which uses shared constraint. Exception occurs during binding phase

Exception:

Property [somePackage.User.email] references shared constraint [email:null], which doesn't exist!

Domain:

class User {
    String email
    static constraints = {
        email(shared: 'email', unique: true)
}

Command

class UpdateClientCommand {
    String email

    static constraints = {
        importFrom User
    }

}

Stacktrace:

Property [clearhub.User.email] references shared constraint [email:null], which doesn't exist!. Stacktrace follows:


 Caused by: org.grails.core.exceptions.GrailsConfigurationException: Property [mypackage.User.email] references shared constraint [email:null], which doesn't exist!
        at org.grails.validation.DefaultConstraintEvaluator.applySharedConstraints(DefaultConstraintEvaluator.java:287)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraintsMap(DefaultConstraintEvaluator.java:245)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:132)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:119)
        at org.grails.validation.DefaultConstraintEvaluator.evaluate(DefaultConstraintEvaluator.java:80)
        at org.grails.validation.ConstrainedPropertyBuilder.handleImportFrom(ConstrainedPropertyBuilder.java:173)
        at org.grails.validation.ConstrainedPropertyBuilder.createNode(ConstrainedPropertyBuilder.java:165)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:101)
        at org.grails.validation.ConstrainedPropertyBuilder.doInvokeMethod(ConstrainedPropertyBuilder.java:72)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:67)
        at mypackage.UpdateClientCommand$__clinit__closure1.doCall(ClientController.groovy:47)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraintsMap(DefaultConstraintEvaluator.java:240)
        at org.grails.validation.DefaultConstraintEvaluator.evaluateConstraints(DefaultConstraintEvaluator.java:144)
        at org.grails.validation.DefaultConstraintEvaluator.evaluate(DefaultConstraintEvaluator.java:92)
        at grails.validation.Validateable$Trait$Helper.validate(Validateable.groovy:149)
        at grails.validation.Validateable$Trait$Helper.validate(Validateable.groovy:82)
        ... 37 common frames omitted

Any ideas ?

rgrebski
  • 2,354
  • 20
  • 29
  • After some debugging it seems like such scenario is not supported. I dropped using shared constraints in favor of 'importFrom' – rgrebski Feb 27 '17 at 13:57
  • If there are other fields you can still you use importFrom and exclude that specific field that causes the problem. – V H Feb 27 '17 at 19:02

1 Answers1

0

If you define a constraint as shared - it should be defined in grails.gorm.default.constraints of grails-app/conf/Config.groovy. Let me guess that 'email' is not defined there so you get this exception?

Just remove the "shared: 'email'," from User and import will should work fine.

Useful link: http://mrhaki.blogspot.com.by/2014/03/grails-goodness-combining-constraints.html

Anton Hlinisty
  • 1,441
  • 1
  • 20
  • 35