gpt4 book ai didi

java - ORACLE中与JPA复合PK出现ORA-00904错误

转载 作者:行者123 更新时间:2023-12-02 10:35:19 24 4
gpt4 key购买 nike

我必须在 Oracle 数据库中使用 JPA 映射复合 PK。

我已经关注了与此相关的其他问题 tutorial但我仍然收到以下错误:

java.sql.SQLSyntaxErrorException: ORA-00904: "COMPOSITEI0_"."NAME_1": 无效标识符(其中 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> {

}

最后调用数据库,它只返回 null,因为这只是一个测试,看看它们是否一起工作:

public CompositeIdEto saveCompositeId() {

CompositeIdEntity compositeIdEto = new CompositeIdEntity();
compositeIdEto.setname3("New");
compositeIdEto.setId(new CompositePrimaryKeyTableEmbeddable("ERR", "ER"));

this.compositeIdDao.save(compositeIdEto);

return null;
}

最佳答案

您似乎通过声明一次来复制 name1name2
在实体本身中,然后在可嵌入中。

您似乎只需要实体中可嵌入的 id 和 name3 声明:

   @Entity
@Table(schema = "SCHEMA", name = "TABLE")
public class CompositeIdEntity {

@EmbeddedId
CompositePrimaryKeyTableEmbeddable id;

@Column(name = "NAME3")
private String name3;

关于java - ORACLE中与JPA复合PK出现ORA-00904错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53333823/

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