【问题标题】:Wrong column type - Found: serial, expected: int8错误的列类型 - 找到:串行,预期:int8
【发布时间】:2012-07-27 18:22:16
【问题描述】:

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

init 方法调用失败;嵌套异常是 org.hibernate.HibernateException:错误的列类型 列 event_staff_id 的 public.event_staff。发现:串行,预期: 整数8

我猜这是因为“serial”不是 Postgresql 中的 real 类型,更多的是与序列相关的自动递增整数值的别名。我想有一种干净的方法可以解决这个问题,但是没有使用 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 postgresql grails


    【解决方案1】:

    Hibernate 无法将“串行”转换为有效的 Java 类型。有点像old problem。如果可以的话,将您的数据库 ID 类型更改为 bigint 或 bigserial 而不是串行,就像 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。

    分别尝试这些技巧。

    【讨论】:

    • 谢谢。结果是我需要将班级成员 eventStaffId 从 Long 更改为 Integer。
    猜你喜欢
    • 2013-09-22
    • 1970-01-01
    • 2012-06-08
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    相关资源
    最近更新 更多