Java ORACLE中JPA的复合PK给出ORA-00904错误
我必须在OracleDB中用JPA映射复合PK 我已经关注了与此相关的其他SO问题,但我仍然得到以下错误:Java ORACLE中JPA的复合PK给出ORA-00904错误,java,oracle,jpa,composite-primary-key,Java,Oracle,Jpa,Composite Primary Key,我必须在OracleDB中用JPA映射复合PK 我已经关注了与此相关的其他SO问题,但我仍然得到以下错误: java.sql.SQLSyntaxErrorException:ORA-00904:“COMPOSITEI0”.“NAME_1”:无效标识符(其中NAME_1与PK中一列的名称相关) 这是我的实体(出于数据保护原因未提及实名): My@Embeddeble id类: @Embeddable public class CompositePrimaryKeyTableEmbeddable i
java.sql.SQLSyntaxErrorException:ORA-00904:“COMPOSITEI0”.“NAME_1”:无效标识符
(其中NAME_1与PK中一列的名称相关)
这是我的实体(出于数据保护原因未提及实名):
My@Embeddeble 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> {
}
您似乎在重复
name1
和name2
列,只声明了一次在实体本身中,然后在可嵌入文件中 您似乎只需要在实体中嵌入id和
name3
声明:
@Entity
@Table(schema = "SCHEMA", name = "TABLE")
public class CompositeIdEntity {
@EmbeddedId
CompositePrimaryKeyTableEmbeddable id;
@Column(name = "NAME3")
private String name3;
是的,在我测试的某个时候,ORACLE给了我一个更准确的消息错误,我可以看到我在复制,这就成功了,谢谢!
public CompositeIdEto saveCompositeId() {
CompositeIdEntity compositeIdEto = new CompositeIdEntity();
compositeIdEto.setname3("New");
compositeIdEto.setId(new CompositePrimaryKeyTableEmbeddable("ERR", "ER"));
this.compositeIdDao.save(compositeIdEto);
return null;
}
@Entity
@Table(schema = "SCHEMA", name = "TABLE")
public class CompositeIdEntity {
@EmbeddedId
CompositePrimaryKeyTableEmbeddable id;
@Column(name = "NAME3")
private String name3;