[英]Composite PK with JPA in ORACLE gives ORA-00904 error
我必須在Oracle DB中用JPA映射復合PK。
我已經關注了與本教程相關的其他SO問題,但是仍然出現以下錯誤:
java.sql.SQLSyntaxErrorException: ORA-00904: "COMPOSITEI0_"."NAME_1": Invalid Identifier
(其中NAME_1與作為PK一部分的列之一的名稱有關)
這是我的實體(出於數據保護的原因未提及實名):
@Entity
@Table(schema = "SCHEMA", name = "TABLE")
public class CompositeIdEntity {
@Column(name = "NAME1")
private String name1;
@Column(name = "NAME2")
private String name2;
@Column(name = "NAME3")
private String name3;
@EmbeddedId
CompositePrimaryKeyTableEmbeddable id;
public CompositePrimaryKeyTableEmbeddable getId() {
return this.id;
}
public void setId(CompositePrimaryKeyTableEmbeddable id) {
this.id = id;
}
// other getters and setters
我的@Embeddable id類別:
@Embeddable
public class CompositePrimaryKeyTableEmbeddable implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name="name1")
private String name1;
@Column(name="name2")
private String name2;
public CompositePrimaryKeyTableEmbeddable() {
super();
}
public CompositePrimaryKeyTableEmbeddable(String name1, String name2) {
this.name1 = name1;
this.name2 = name2;
}
我的@Repository:
@Repository
public interface CompositeIdDao extends JpaRepository<CompositeIdEntity, CompositePrimaryKeyTableEmbeddable> {
}
最后調用DB,該DB僅返回null,因為這只是測試是否可以一起使用:
public CompositeIdEto saveCompositeId() {
CompositeIdEntity compositeIdEto = new CompositeIdEntity();
compositeIdEto.setname3("New");
compositeIdEto.setId(new CompositePrimaryKeyTableEmbeddable("ERR", "ER"));
this.compositeIdDao.save(compositeIdEto);
return null;
}
似乎您通過聲明一次來復制name1
和name2
列
在實體本身中,然后在可嵌入對象中。
您似乎只需要在實體中嵌入id和name3
聲明:
@Entity
@Table(schema = "SCHEMA", name = "TABLE")
public class CompositeIdEntity {
@EmbeddedId
CompositePrimaryKeyTableEmbeddable id;
@Column(name = "NAME3")
private String name3;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.