RC.*_*RC. 3 postgresql grails hibernate
我正在编写我的第一个Grails应用程序,并且已经使用Grails应用程序生成器反转了现有的Postgresql模式。(GRAG)运行应用程序时,出现错误:
调用init方法失败;嵌套异常是org.hibernate.HibernateException:public.event_staff中列event_staff_id的列类型错误。找到:串行,预期:int8
我猜这是由于“串行”不是Postgresql中的真实类型,并且更多是与序列相关的自动递增整数值的别名。我想有一个解决此问题的干净方法,但是由于没有Hibernate的经验,我不确定前进的最佳方法。
这是有问题的课程:
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}"
}
}
Run Code Online (Sandbox Code Playgroud)
Hibernate无法将'serial'转换为有效的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.
Run Code Online (Sandbox Code Playgroud)
您仍然可以尝试将ID类型更改为Integer而不是Long。
单独尝试这些技巧。
| 归档时间: |
|
| 查看次数: |
8211 次 |
| 最近记录: |