我在hibernate和JPA中創建了父類和子類。當我嘗試堅持這個類時,我得到一個SQL異常,聲明「無效列索引」。hibernate集合 - 無效的列索引
這是父類:
@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時,我收到以下消息:
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
任何幫助,將不勝感激。我已經嘗試了一些東西,如設置爲false,但沒有運氣。我看到有一個問題提到組合鍵可能存在問題。當它只是作爲父項的一部分存在時,是否真的必須在子項上創建唯一的序列列?
我index'改變字段名''到dimensionIndex',但我還是收到相同的錯誤 – mystafer 2012-08-03 02:48:05
而且我相信你已經爲該列準備了吸氣劑了嗎? – 2012-08-03 02:55:17
是的。我對所有列都有getter和setter,我也將'index'的名字改名爲'dimensionIndex'。 – mystafer 2012-08-03 13:00:59