Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
hibernate集合-列索引无效_Hibernate_Jpa_Annotations - Fatal编程技术网

hibernate集合-列索引无效

hibernate集合-列索引无效,hibernate,jpa,annotations,Hibernate,Jpa,Annotations,我在hibernate和JPA中创建了一个父类和子类。当我试图持久化这个类时,我得到一个SQL异常,声明“无效的列索引” 这是父类: @Entity @Table(name = "vnd_base_file_format") public class VendorBaseFileFormat implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(nam

我在hibernate和JPA中创建了一个父类和子类。当我试图持久化这个类时,我得到一个SQL异常,声明“无效的列索引”

这是父类:

@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;
我只需创建父类并向其中添加一个子类。调用entityManager.persist时,会收到以下消息:

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,但没有成功。我确实看到有一个问题提到了复合键可能存在问题。当子项仅作为父项的一部分存在时,我真的必须在子项上创建一个唯一的序列列吗?

我可以看到您的orderBy注释将字段的名称作为“索引”。您应该为另一个类的索引提供一个getter,或者尝试将其更改为“dimension_index”。希望它能解决这个问题。

我认为索引列出现问题是因为您使用列表集合来保存关系。你可以做这样的事情:

1) 将列表更改为在VendorBaseFileFormat类中设置


2) 将@IndexColumn(name=“idx”)注释添加到类中,并通过此列显式指定将用于保存列表索引的内容。您还应该将此列添加到*vnd\U base\U file\U format\U dim*表中。在这个使用列表的双向一对多映射的示例中(第8节)。

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

我需要的主要信息可以在本文中找到


帮助我解决这个问题的问题已经发布了

我将字段名
index
更改为
dimensionIndex
,但我仍然收到了相同的错误,我相信你已经有了该列的getter正确吗?是的。我为所有列都设置了getter和setter,并将
索引
也重命名为
维度索引
。我尝试使用@IndexColumn而不是@OrderBy,但得到了相同的错误
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