首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@ElementCollection setField 00942: ORA-00942

@ElementCollection setField 00942: ORA-00942
EN

Stack Overflow用户
提问于 2022-08-10 12:32:04
回答 1查看 32关注 0票数 0

我有两个java类,其中一个类以@ElementCollection的列表形式包含另一个类。当我试图设置该列表时,会发生以下错误:

代码语言:javascript
复制
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

Error Code: 942
Call: SELECT t0.VERSIONS FROM MainProcess_VERSIONS t0 WHERE (t0.MainProcess_SUBJECT_ID = ?)
bind => [#id]
Query: DirectReadQuery(name="versions" sql="SELECT t0.VERSIONS 
FROM MainProcess_VERSIONS t0 WHERE (t0.MainProcess_SUBJECT_ID = ?)")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:683)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:526)
.
.
.
at ...Editor.MAINPROCESS._persistence_propertyChange(MAINPROCESS.java)
at ...Editor.MAINPROCESS._persistence_set_versions(MAINPROCESS.java)
at ...MAINPROCESS.setVersions(MAINPROCESS.java:79)
at ...DataModel.fillSubprocessSubject(DataModel.java:643)
at ...DataModel.load(DataModel.java:321)

如果删除@ElementCollection,则会得到以下错误

代码语言:javascript
复制
Error Code: 942
Call: 
SELECT t1.ACT_VERSION, t1.SUBJECT_ID, t1.ACT_VERSION_REMARK,
  t1.ACT_VALID_TO, t1.ACT_VERSION_ACCEPTED, t1.NORMALRETURNVALUES, t1.ACT_VALID_FROM 
FROM MAINPROCESS_MAINPROCESSVERSION t0, MAINPROCESSVERSION t1
WHERE ((t0.MainProcess_SUBJECT_ID = ?) AND ((t1.SUBJECT_ID = t0.SUBJECT_ID) 
AND (t1.ACT_VERSION = t0.ACT_VERSION)))
    bind => [#id]

这是我的课,

MainProcess:

代码语言:javascript
复制
@Entity
public class MainProcess implements Serializable {

  @Id
  @Column(name = "SUBJECT_ID", nullable = false)
  private Long subjectId;
  
  ...other columns

  @ElementCollection
  private List<MainProcessVersion> versions = new ArrayList<MainProcessVersion>();

  public MainProcess() {
  }

  public void setVersions(List<MainProcessVersion> versions) {
    this.versions = versions;
  }

  public List<MainProcessVersion> getVersions() {
    return versions;
  }

  other getters and setters...
}

MainProcessVersion:

代码语言:javascript
复制
@Entity
@IdClass(MainProcessVersionPK.class)
public class MainProcessVersion implements Serializable {

  @Id
  @Column(name = "SUBJECT_ID", nullable = false)
  @XmlTransient
  private Long subjectId;

  @Id
  @Column(name = "ACT_VERSION")
  private Long actVersion;

  ...other columns

  private List<String> normalReturnValues;

  public MainProcessVersion() {
  }

  getters and setters...

}

以及发生错误的函数:

代码语言:javascript
复制
private MainProcess fillSubprocessSubject(Long Id) {
    MainProcess p = someFacade.getProcess(Id);
    List<MainProcessVersion> versions = someFacade.getProcessVersions(Id);
    p.setVersions(versions); //error is here
    return p;
}

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-12 13:55:06

我设法解决了我的问题。最重要的是理解@ElementCollection@OneToMany注释之间的区别。我无法更好地像this那样解释。

所以问题是我的MainProcessVersion.java是用@Entity注释的,因此我不能在MainProcess.java中添加@ElementCollection注释。

代码语言:javascript
复制
 @ElementCollection //One cannot use this annotation because MainProcessVersion is an entity.
 private List<MainProcessVersion> versions = new ArrayList<MainProcessVersion>();

但是我需要实体,所以我创建的resultRow类与我的实体类是相同的,除了注释。在查询选择之后,我将结果转换为新的resultRow类,并可以在MainProcess.java中设置该列表。

我的resultRow课程:

代码语言:javascript
复制
public class MainProcessVersionResultRow implements Serializable {
    
    private Long subjectId;
    ...other code
}

我以前的MainProcess课

代码语言:javascript
复制
 @Entity
public class MainProcess implements Serializable {

    @Id
    @Column(name = "SUBJECT_ID", nullable = false)
    private Long subjectId;

    ...other columns
    
    //without @ElementCollection and the new resultRow object type
    private List<MainProcessVersionResultRow> versions = new ArrayList<MainProcessVersionResultRow>();

    public MainProcess() {
    }

    ...getters. setters
}

然后,我将我的实体“转换”到resultRow类:

代码语言:javascript
复制
private MainProcess fillSubprocessSubject(Long subjectId) {
        MainProcess p =
            someFacade.getSubprocessSubject(subjectId);
        List<MainProcessVersion> versions = someFacade.getProcessVersions(subjectId);
        List<MainProcessVersionResultRow> versionResultRows = new ArrayList<MainProcessVersionResultRow>();

        for (MainProcessVersion vs : versions) {
            MainProcessVersionResultRow versionSingleResultRow = new MainProcessVersionResultRow(vs);
            versionSingleResultRow.setNormalReturnValues(processReturnValues(p.getSubjectId(), vs.getActVersion()));
            versionResultRows.add(versionSingleResultRow);
        }

        p.setVersions(versionResultRows); //does not throw an error any more
        return p;
    }

因此,结论:不要在具有@Entity注释的类上使用@ElementCollection

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73306391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档