休眠集合 - 无效的列索引 [英] hibernate collection - invalid column index

查看:22
本文介绍了休眠集合 - 无效的列索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 hibernate 和 JPA 中创建了一个父类和子类.当我尝试保留该类时,我收到一个 SQL 异常,指出无效的列索引".

I have created a parent and child class in hibernate and JPA. When I attempt to persist the class I get a SQL exception stating "invalid column index".

这是父类:

@Entity
@Table(name = "vnd_base_file_format")
public class VendorBaseFileFormat implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "base_file_format_id")
    private int baseFileFormatId;

    @Column(name = "vendor_id")
    private int vendorId;

    @Column(name = "format_name")
    private String formatName;

    @Column(name = "enabled")
    private boolean enabled;

    @Column(name = "month_year_format")
    private String monthYearFormat;

    @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="base_file_format_id", nullable=false)
    @OrderBy("index")
    private List<VendorBaseFileDimension> dimensions;

这是子类:

@Entity
@Table(name = "vnd_base_file_format_dim")
public class VendorBaseFileDimension implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "dimension_id")
    private int dimensionId;

    @Column(name = "alternate_name")
    private String alternateName;

    @Column(name = "dimension_index")
    private int index;

    @Id
    @ManyToOne
    @JoinColumn(name="base_file_format_id", nullable=false, insertable=false)
    private VendorBaseFileFormat format;

我只是创建了父类并向其中添加了一个子类.当我调用 entityManager.persist 时,我收到以下消息:

I simply create the parent class and add one child class to it. When I call entityManager.persist I get the following message:

Hibernate: insert into vnd_base_file_format (enabled, format_name, month_year_format, vendor_id, base_file_format_id) values (?, ?, ?, ?, ?)
Hibernate: insert into vnd_base_file_format_dim (alternate_name, dimension_index, base_file_format_id, dimension_id) values (?, ?, ?, ?)
[21:53:01.159] WARN  JDBCExceptionReporter - SQL Error: 17003, SQLState: 99999
[21:53:01.159] ERROR JDBCExceptionReporter - Invalid column index

任何帮助将不胜感激.我尝试了一些事情,比如将 insertable 设置为 false,但没有运气.我确实看到一个问题,提到复合键可能存在问题.当它只作为父级的一部分存在时,我真的必须在子级上创建一个唯一的序列列吗?

Any help would be appreciated. I have tried a few things like setting insertable to false, but no luck. I did see one question out there that mentioned there might be a problem with composite keys. Do I really have to create a unique sequence column on the child when it is only going to exist as part of the parent?

推荐答案

我发现了另一个问题,该问题的解决方案很有帮助.我将单个 id 列更改为复合键对象,这似乎对我有用.

I found another question with a solution that was helpful. I changed the individual id columns into a composite key object and this seemed to work for me.

我需要的主要信息见这篇文章这里.

The main information that I needed was found in this article here.

帮助我弄清楚的问题已发布此处.

The question that helped me figure it out was posted here.

这篇关于休眠集合 - 无效的列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆