grails-data-mapping
grails-data-mapping copied to clipboard
unique constraint not working
While upgrading from grails 3.1.15 to 3.3.11 we noticed a regression on the unique constraint. More specifically, a multi-column unique constraint on the same domain class.
The Domain has a reference to itself and the identifier is supposed to be unique between all children of the same parent.
class Domain {
String identifier
boolean is_parent
Domain parent
static constraints = {
identifier(nullable: true, blank: true, unique: 'parent')
parent(nullable: true)
}
}
We noticed that the query for the unique check is incomplete:
select this_.id as y0_ from domain this_ where this_.identifier=? limit ?
the parent is not even considered
This used to work in grails 3.1.15 which generates this query instead:
select this_.id as id1_0_0_, this_.version as version2_0_0_, this_.identifier as identifi3_0_0_, this_.is_parent as is_paren4_0_0_, this_.parent_id as parent_i5_0_0_ from domain this_ where this_.identifier=? and this_.parent_id=?
The sample project has an integration test that showcases this.
Task List
- [X] Steps to reproduce provided
- [ ] Stacktrace (if present) provided
- [X] Example that reproduces the problem uploaded to Github
- [X] Full description of the issue provided (see below)
Steps to Reproduce
- Clone the sample repo and run
DomainIntegrationTest
- last test fails
Expected Behaviour
spec should not fail
Actual Behaviour
spec fails - the unique constraint in the Domain class is not working as expected
Environment Information
- Operating System: MacOS 10.14.6
- GORM Version: 6.1.12.RELEASE
- Grails Version (if using Grails): 3.3.11
- JDK Version: openjdk version "1.8.0_232"
Example Application
https://github.com/bp-FLN/uniqueConstraint/
This should be fixed in GORM 7.0.2
@jameskleeh i tried GORM 7.0.2 but can't make it work. i always get this exception when running the integration test:
java.lang.NoSuchMethodError: org.codehaus.groovy.runtime.DefaultGroovyMethods.collect([Ljava/lang/Object;Lgroovy/lang/Closure;)Ljava/util/List;
at grails.plugin.hibernate.HibernateGrailsPlugin.doWithSpring_closure1(HibernateGrailsPlugin.groovy:65)
Right it requires the new spring version that is used in grails 4
On Fri, Jan 24, 2020 at 6:23 PM Florian Langenhahn [email protected] wrote:
@jameskleeh https://github.com/jameskleeh i tried GORM 7.0.2 but can't make it work. i always get this exception:
at grails.plugin.hibernate.HibernateGrailsPlugin.doWithSpring_closure1(HibernateGrailsPlugin.groovy:65)```
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/grails/grails-data-mapping/issues/1278?email_source=notifications&email_token=AAMCVLPGG4H2SSGS5MAYF3LQ7NZ67A5CNFSM4KLLRR6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ4MOYY#issuecomment-578340707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMCVLM562CYQ6PPAZLHWQDQ7NZ67ANCNFSM4KLLRR6A .
unfortunately, we can't upgrade to grails 4 yet and have to stick with grails 3.3.x. is there any chance that this fix gets backported to GORM 6.x? or is there some workaround instead?