Grails (Hibernate) does select before insert without passing id argument value
I'm starting more serious tests of my grails web-app and it was time to move from hsqldb to postgres. Eve开发者_JAVA百科rything went more or less ok, however I'm getting an error in Bootstrap when creating test data. Hibernate tries to do a select before inserting a row into the database. Unfortunately, when doing so it does not pass an argument to the select and I'm getting exception saying the parameter 1 value was not specified.
Here's my domain class:
class User {
static constraints = {
deviceId(
blank: false,
unique: true,
)
userName(nullable: true, size: 5..15, blank: false, unique: true)
password(nullable: true, size: 5..15, blank: false)
email(nullable: true, email: true, blank: false, unique: true)
blockedUsers(unique: true)
}
static mapping = {
table "player"
deviceId indexColumn: [name: "deviceId", unique: true]
}
static mappedBy = [inbox: 'userTo', outbox: 'userFrom']
static hasMany = [profiles: Profile, inbox: Message, outbox: Message, blockedUsers: User]
List<User> blockedUsers = new ArrayList<User>()
String deviceId
String userName
String email
String password
Boolean readyForExport = false
Boolean newUser = false
[...]
}
so there's nothing special about it. Before this error I've got quite a few .save(flush:true) commands on other domains and everything is fine. It's just this one that throws the error :/
These are the lines responsible for this error.
User userA = new User(userName: "test", password: "dkjughey3htg", email: "integration@test.com", deviceId: 'intTestDevice')
userA.save(flush:true)
Any tips why this would happen?
I haven't tested this, but I think your problem is in:
blockedUsers(unique:true)
Is there a reason why you're specifying blockedUsers as a List rather than GORM's default of Set? With Set, uniqueness of members is automatic, and then you don't have to use the unique constraint, which doesn't work as you might expect on one-to-many properties. Also, this is unrelated, but plaintext passwords are naughty.
精彩评论