【问题标题】:Why Hibernate creates sequence for column referring on *-to-many table?为什么 Hibernate 为 *-to-many 表上的列引用创建序列?
【发布时间】:2018-05-19 13:29:01
【问题描述】:

大家好!

我遇到了一个奇怪的问题。我正在尝试创建一个简单的数据库模式。但是 hibernate 为在 *-to-many 表中引用 id-columns 的列创建了额外的序列。

我用 @Id, @Column(columnDefinition = "serial"), @GeneratedValue(strategy = GenerationType.IDENTITY)BIGSERIAL 类型创建序列(但我不希望休眠将外键设为BIGSERIAL 的列)。

我的实体有这样的结构

    @Entity
    public class PropertyItem {

        //id's here ...

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "property_id")
        private Property property;

        //getters and setters ...
    }

    @Entity
    public class Property {

        //id's here ...

        @OneToMany(mappedBy = "property")
        private List<PropertyItem> propertyItems;

        //getters and setters ...
    }

请帮我避免这种情况:(

谢谢你????

【问题讨论】:

    标签: java hibernate orm hibernate-mapping


    【解决方案1】:

    我明白了!

    这个注解@Column(columnDefinition = "serial")是多余的。

    【讨论】:

      猜你喜欢
      • 2014-08-09
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 2019-07-26
      相关资源
      最近更新 更多