java.sql.SQLException:ORA-00942:JPA entityManager.createQuery()

时间:2017-05-26 12:54:10

标签: java oracle hibernate jpa

我正在使用 JPA createquery API来获取数据。

这是我的查询数据

    @PersistenceContext
    EntityManager entityManager;
    @Override
    public List<String> fetchAllReleaseNumbers() {

        Query query = entityManager.createQuery("SELECT release FROM ReleaseModel", String.class);

        return query.getResultList();
    }

这是我的pojo课程。

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "dbname.tablenamefromDB")
public class ReleaseModel {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "dbcolumnname", unique = true, nullable = false)
    private String release;

    @Column(name = "dbcolumnname")
    private String releaseDesc;

    @Column(name = "dbcolumnname")
    private Integer releaseStatus;

    @Column(name = "dbcolumnname")
    private Integer releaseMode;


    public String getRelease() {
        return release;
    }

    public void setRelease(String release) {
        this.release = release;
    }

    public String getReleaseDesc() {
        return releaseDesc;
    }

    public void setReleaseDesc(String releaseDesc) {
        this.releaseDesc = releaseDesc;
    }

    public Integer getReleaseStatus() {
        return releaseStatus;
    }

    public void setReleaseStatus(Integer releaseStatus) {
        this.releaseStatus = releaseStatus;
    }

    public Integer getReleaseMode() {
        return releaseMode;
    }

    public void setReleaseMode(Integer releaseMode) {
        this.releaseMode = releaseMode;
    }

}

虽然这个表存在于db中,但它的抛出并不存在。我犯错的任何想法。 我试过是否可以为表名赋予任何别名。 我只为createQuery使用pojo类名。

TIA。

1 个答案:

答案 0 :(得分:3)

您应该通过这种方式指定架构名称

@Table(schema = "dbname", name = "tablenamefromDB")

您的映射不正确:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "dbcolumnname", unique = true, nullable = false)
private String release;

我认为String无法自动生成。 此外,您的所有列都有dbcolumnname名称。