gpt4 book ai didi

hibernate - 列类型错误 - 发现 : serial, 预期:int8

转载 作者:行者123 更新时间:2023-12-02 21:19:29 25 4
gpt4 key购买 nike

我正在编写我的第一个 Grails 应用程序,并且使用 Grails 应用程序生成器反转了现有的 Postgresql 架构。 (GRAG)当我运行该应用程序时,出现错误:

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

我猜这是因为“serial”不是 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}"
}
}

最佳答案

Hibernate 无法将“串行”转换为有效的 Java 类型。这有点像old problem 。如果可以的话,将数据库 ID 类型更改为 bigint 或 bigserial 而不是 serial,例如 this guy做了,它可能会解决你的问题。如果没有,请尝试使用以下方式指定列的类型:

id generator:'identity', column:'event_staff_id', 
name: 'eventStaffId', type: 'serial' //though I don't know if 'serial' will work in this dialect.

您仍然可以尝试将 id 类型更改为 Integer 而不是 Long。

分别尝试这些技巧。

关于hibernate - 列类型错误 - 发现 : serial, 预期:int8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11693509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com