我试图在Oracle数据库中保留实体对象时遇到此异常,我在将JPA项目切换为 EclipseLink 2.0 来自 Hibernate ,我正在使用“实体继承”,如果这可能与它有任何关系(我非常怀疑)。
*
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00957: duplicate column name
Error Code: 957
Call: INSERT INTO SUREC (ID, PERSON_ID, SURECID, VERSIYONNO, FAZ, FORM_TARIH, DURUMKODU_ID, surecId) VALUES (...
*
异常消息表明SURECID在SQL中生成了两次,似乎导致了重复列错误,但是surecId被定义为属性并在实体类中注释为discriminator列:(见下文)
基本实体类类似于:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name = "surecId")
public class Surec implements java.io.Serializable {
private static final long serialVersionUID = -6008473677883005878L;
@Column(name = "ID")
private Long id;
@Basic(optional = false)
@Column(name = "FAZ")
private int faz;
@Basic(optional = false)
@Column(name = "FORM_TARIH")
@Temporal(TemporalType.DATE)
private Date formTarih;
@Column(name = "PERSON_ID")
private Integer personId;
// @Column(name = "SURECID", updatable = false, length=17)
@Column(updatable = false, length=17)
private String surecId;
@Column(name = "VERSIYONNO")
private Long versiyonno;
@JoinColumn(name = "DURUMKODU_ID", referencedColumnName = "ID")
@ManyToOne
private DurumKod durumKodu;
public Surec() {
}
public Surec(String surecId) {
this.surecId = surecId;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
.
.
.
public String getSurecId() {
return surecId;
}
public void setSurecId(String surecId) {
this.surecId = surecId;
}
.
.
.
我评论了“@Column(name = ...”注释jus,看它是否会导致重复列错误,但它没有用完。
以下是扩展 Surec.java 的多态实体:
@Entity
@DiscriminatorValue("atf")
public class MailOrder extends Surec {
private static final long serialVersionUID = 8333637555543614502L;
@Column(name = "AMOUNT")
private Double amount;
@Basic(optional = false)
@Column(name = "CURRENCY", length = 17)
private String currency;
@Column(name = "BANK")
private String Bank;
@Column(name = "ACCOUNT_ID", length = 31)
private String accountId;
@Column(name = "INVOICE_ID")
private Integer invoiceId;
public MailOrder() {
}
public MailOrder(String surecId) {
super(surecId);
}
public String getCurrency() {
return currency;
}
.
.
.
当我尝试持久保存这个子实体时会发生错误。 它不会覆盖其超类的任何属性,虽然我不确定它是否是构造函数...
任何建议解决问题(以及确认任何可能的EclipseLink或Oracle(或我的!)错误都将受到赞赏。
答案 0 :(得分:3)
如果您有使用此字段的关系映射,并且与区分大小写有关,则这是一个常见问题。尝试将descriminator colum指示为 @DiscriminatorColumn(name =“SURECID”)
默认情况下,EclipseLink区分大小写,这就是为什么surecId被视为与SURECID不同的字段。您可以使用eclipselink.jpa.uppercase-column-names属性使EclipseLink不区分大小写,当设置为true时,强制EclipseLink在字段名称比较时使用大写。
答案 1 :(得分:0)
我猜您需要将该属性标记为insertable = false, updateable = false
,因为它已作为鉴别器插入:
@Column(insertable = false, updatable = false, length=17)
private String surecId;