hibernate集合 - 无效的列索引 [英] hibernate collection - invalid column index
问题描述
我在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)
私有布尔启用;
@Column(name =month_year_format)
private String monthYearFormat;
@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE})
@JoinColumn(name =base_file_format_id,nullable = false)
@OrderBy(index )
私人清单< VendorBaseFileDimension>尺寸;
这是子类:
@Entity
@Table(name =vnd_base_file_format_dim)
public class VendorBaseFileDimension实现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,可插入= false)
私有VendorBaseFileFormat格式;
我只需创建父类并向其添加一个子类。当我调用entityManager.persist时,我收到以下消息:
$ b $ pre $ Hibernate:insert into vnd_base_file_format(enabled,format_name,month_year_format,vendor_id, base_file_format_id)值(?,?,?,?,?)
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错误:17003,SQLState:99999
[21:53:01.159]错误JDBCExceptionReporter - 无效的列索引
任何帮助将不胜感激。我已经尝试了一些东西,如设置为false,但没有运气。我看到有一个问题提到组合键可能存在问题。当它只是作为父项的一部分存在时,我真的必须在子项上创建唯一的序列列吗?
>我发现另一个有助于解决方案的问题。我将个人id列更改为复合键对象,这似乎适用于我。我需要的主要信息在本文中找到 here。
帮助我弄清楚的问题发布了 here。
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".
This is the parent class:
@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;
This is the child class:
@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;
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
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?
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.
这篇关于hibernate集合 - 无效的列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!