Fabschu opened a new issue, #14503:
URL: https://github.com/apache/grails-core/issues/14503
### Task List
- [x] Steps to reproduce provided
- [x] 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
1. Create Domain Class with unique constraint with multiple columns:
```
package sec
import org.springframework.http.HttpMethod
class Requestmap {
String name
String description
String url
String configAttribute
HttpMethod httpMethod
static mapping = {
cache true
}
static constraints = {
url blank: false, unique: 'httpMethod'
configAttribute blank: false
name blank:false
description nullable:true
httpMethod nullable:true
}
}
```
2. Create and Save new Domain Objects
```
new Requestmap(url: '/test1/**', configAttribute:
"IS_AUTHENTICATED_ANONYMOUSLY",name:"Assets",
httpMethod:"POST").save(failOnError:true)
new Requestmap(url: '/test1/**', configAttribute:
"IS_AUTHENTICATED_ANONYMOUSLY",name:"Assets").save(failOnError:true)
```
### Expected Behaviour
- no validation exceptions
- both objects saved to the database
### Actual Behaviour
- validation exception is thrown. Null value of httpMethod seems to be
ignored in the created SQL-Query
```
grails.validation.ValidationException: Validation Error(s) occurred during
save():
- Field error in object 'sec.Requestmap' on field 'url': rejected value
[/test1/**]; codes
[sec.Requestmap.url.unique.error.sec.Requestmap.url,sec.Requestmap.url.unique.error.url,sec.Requestmap.url.unique.error.java.lang.String,sec.Requestmap.url.unique.error,requestmap.url.unique.error.sec.Requestmap.url,requestmap.url.unique.error.url,requestmap.url.unique.error.java.lang.String,requestmap.url.unique.error,sec.Requestmap.url.unique.sec.Requestmap.url,sec.Requestmap.url.unique.url,sec.Requestmap.url.unique.java.lang.String,sec.Requestmap.url.unique,requestmap.url.unique.sec.Requestmap.url,requestmap.url.unique.url,requestmap.url.unique.java.lang.String,requestmap.url.unique,unique.sec.Requestmap.url,unique.url,unique.java.lang.String,unique];
arguments [url,class sec.Requestmap,/test1/**]; default message [Die
Eigenschaft [{0}] des Typs [{1}] mit dem Wert [{2}] darf nur einmal vorkommen]
```
First SQL-Query with POST as httpMethod:
```
2020-07-21 11:24:32.301 DEBUG --- [ restartedMain] org.hibernate.SQL
: select this_.id as y0_ from requestmap this_ where
this_.url=? and this_.http_method=? limit ?
2020-07-21 11:24:32.301 DEBUG --- [ restartedMain] org.hibernate.SQL
: select this_.id as y0_ from requestmap this_ where
this_.url=? and this_.http_method=? limit ?
2020-07-21 11:24:32.307 TRACE --- [ restartedMain]
o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] -
[/test1/**]
2020-07-21 11:24:32.307 TRACE --- [ restartedMain]
o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] -
[/test1/**]
2020-07-21 11:24:32.307 TRACE --- [ restartedMain]
o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] -
[POST]
2020-07-21 11:24:32.307 TRACE --- [ restartedMain]
o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] -
[POST]
```
Second SQL-Query with null as httpMethod:
```
2020-07-21 11:24:32.344 DEBUG --- [ restartedMain] org.hibernate.SQL
: select this_.id as y0_ from requestmap this_ where
this_.url=? limit ?
2020-07-21 11:24:32.344 DEBUG --- [ restartedMain] org.hibernate.SQL
: select this_.id as y0_ from requestmap this_ where
this_.url=? limit ?
2020-07-21 11:24:32.344 TRACE --- [ restartedMain]
o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] -
[/test1/**]
2020-07-21 11:24:32.344 TRACE --- [ restartedMain]
o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] -
[/test1/**]
```
There is no where clause for the httpMethod column in the second SQL-Query
### Environment Information
- **Operating System**: Windows 10
- **GORM Version:7.0.4.RELEASE
- **Grails Version:4.0.3
- **JDK Version:1.8.0_251
### Example Application
https://github.com/Fabschu/multiple-unique-constraint-error
RequestMaps Objects are created in the Bootstrap.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]