Issue
I am using JPA createquery API to fetch the data.
Here is my query data
@PersistenceContext
EntityManager entityManager;
@Override
public List<String> fetchAllReleaseNumbers() {
Query query = entityManager.createQuery("SELECT release FROM ReleaseModel", String.class);
return query.getResultList();
}
and here is my pojo class.
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;
}
}
Though the table exists in db its throwing not exist.Any ideas where I made mistake. I tried whether any aliases can be given to the table name. I am using pojo class name only for createQuery.
TIA.
Solution
You should specify a schema name by this way
@Table(schema = "dbname", name = "tablenamefromDB")
You have an incorrect mapping:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "dbcolumnname", unique = true, nullable = false)
private String release;
I think String
can't be auto generated.
Also all your columns have dbcolumnname
name.
Answered By - v.ladynev
Answer Checked By - Marie Seifert (JavaFixing Admin)