3
votes

I'm using grails 3.02 and all was fine, but since I moved several domain classes from another grails project I started seeing this error when I do start integration tests:

grails.validation.exceptions.ConstraintException: Exception thrown applying constraint [unique] to class [class com.mypackage.Individual] for value [true]: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6397593b has not been refreshed yet

The domain class code:

class Individual {

 String institutionId
 String email


 static mapping = {
    table 'db.individual'
    id generator: 'sequence', params: [sequence: 'db.individual_id_sequence']
    institutionId index: 'db.individual_institution_id_idx'
    email index: 'db.individual_email_idx'
 }

 static constraints = {
    institutionId(blank: false)
    email(unique: true)
 }
}

The strange thing is: this code is working in another project but does not want to work in this one, in where I moved it to. I compared configs(application.yml and application.groovy and build.gradle) - but all is basically the same.

Any help, grails gurus?

1
try with removing individual_email_ids from email field. - Vinay Prajapati
Have you found a solution? I've just received the same error - GUL

1 Answers

0
votes

I think I have found why I had this exception. It was not related to constrains at all.

I just had some other fields in my domain class which used to be calculated, so it was unmapped field. But grails used to try to map this field into a real database column. Once I've defined my own getter(in which the field initializes) for this calculated field all became fine.

But the grails exception btw is stupid and disorienting - it does not describe the root cause at all.