Hibernate 列类型错误-找到:串行,应为:int8
我正在编写我的第一个Grails应用程序,并使用Grails应用程序生成器反转了我现有的Postgresql模式。(GRAG)当我运行应用程序时,我得到错误: 调用init方法失败;嵌套异常是 org.hibernate.hibernateeexception:中的列类型错误 public.event\u staff用于列event\u staff\u id。找到:序列,应为: int8 我猜这是因为“serial”在Postgresql中不是一个真正的类型,而更多的是一个绑定到序列的自动递增整数值的别名。我想有一个干净的方法来解决这个问题,但由于没有使用Hibernate的经验,我不确定前进的最佳方法 这是一节有问题的课:Hibernate 列类型错误-找到:串行,应为:int8,hibernate,postgresql,grails,Hibernate,Postgresql,Grails,我正在编写我的第一个Grails应用程序,并使用Grails应用程序生成器反转了我现有的Postgresql模式。(GRAG)当我运行应用程序时,我得到错误: 调用init方法失败;嵌套异常是 org.hibernate.hibernateeexception:中的列类型错误 public.event\u staff用于列event\u staff\u id。找到:序列,应为: int8 我猜这是因为“serial”在Postgresql中不是一个真正的类型,而更多的是一个绑定到序列的自动递增整
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无法将“串行”转换为有效的Java类型。这有点像是一场战争。如果可以,将数据库id类型更改为bigint或bigserial而不是serial,就像这样,它可能会解决您的问题。如果不是,请尝试使用以下命令指定列的类型:
id generator:'identity', column:'event_staff_id',
name: 'eventStaffId', type: 'serial' //though I don't know if 'serial' will work in this dialect.
您仍然可以尝试将id类型更改为整数而不是Long
请分别尝试这些技巧。谢谢。最后,我需要将我的类成员eventStaffId从Long改为Integer。