gpt4 book ai didi

java - EclipseLink 是否会导致 ORA-00957 : duplicate column name error because of a @DiscriminatorColumn in a polymorphic entity?

转载 作者:行者123 更新时间:2023-12-02 00:44:34 24 4
gpt4 key购买 nike

我在尝试将 实体 对象保留在 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 作为属性定义了一次,并在实体类中注释为鉴别器列:(见下文)

基本实体类类似于:

@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=...”注释,只是为了看看它是否会导致重复列错误,但没有成功。

下面是扩展上面 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;
}
.
.
.

当我尝试保留这个子实体时,会发生错误。它不会覆盖其父类(super class)的任何属性,尽管我不确定它是否是构造函数......

任何解决问题的建议(以及对任何可能的 EclipseLink 或 Oracle(或我的!)错误的确认)将不胜感激。

最佳答案

如果您有使用此字段的关系映射,并且与区分大小写有关,那么这是一个常见问题。尝试将鉴别器列指示为@DiscriminatorColumn(名称 = "SURECID")

EclipseLink 默认情况下区分大小写,这就是 SurecId 被视为与 SURECID 不同的字段的原因。您可以使用 eclipselink.jpa.uppercase-column-names 属性使 EclipseLink 不区分大小写,该属性设置为 true 时,会强制 EclipseLink 在字段名称比较中使用大写。

关于java - EclipseLink 是否会导致 ORA-00957 : duplicate column name error because of a @DiscriminatorColumn in a polymorphic entity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5369101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com