I’m writing my first Grails app and I’ve reversed my existing Postgresql schema using the Grails Application Generator. (GRAG) When I run the app, I get the error:
Invocation of init method failed; nested exception is
org.hibernate.HibernateException: Wrong column type in
public.event_staff for column event_staff_id. Found: serial, expected:
int8
I’m guessing this is due to “serial” not being a real type in Postgresql and more of an alias for an auto incrementing integer value that is tied to a sequence. I imagine there is a clean way to work around this issue, but having no experience with Hibernate I’m not sure the best way to move forward.
Here’s the class in question:
class EventStaff {
static mapping = {
table 'event_staff'
// version is set to false, because this
// isn't available by default for legacy databases
version false
id generator:'identity', column:'event_staff_id', name: 'eventStaffId'
staffMemberIdStaffMember column:'staff_member_id'
gameIdGame column:'game_id'
}
Long eventStaffId
Boolean shouldNotify
Date created
Date modified
// Relation
StaffMember staffMemberIdStaffMember
// Relation
Game gameIdGame
static constraints = {
eventStaffId()
shouldNotify()
created()
modified()
staffMemberIdStaffMember()
gameIdGame()
}
String toString() {
return "${eventStaffId}"
}
}
Hibernate is not being able to convert ‘serial’ to a valid Java type. It’s kind of an old problem. If you can, change your database id type to bigint or bigserial instead of serial, like this guy did, it will probably solve your problem. If not, try specifying the type of the column with:
Still you can try to change your id type to Integer instead of Long.
Try these tips separately.