我有这个 Java 对象,我想用它来显示数据库中的数据。
public TData td;
public class TData {
private long id;
private String key;
private String language;
private String translation;
public TData() {
};
public TData(long id, String key, String language, String translation) {
// super();
this.id = id;
this.key = key;
this.language = language;
this.translation = translation;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getTranslation() {
return translation;
}
public void setTranslation(String translation) {
this.translation = translation;
}
}
public TData getDataObj() {
return td;
}
这是我想用来获取数据的数据库表:
CREATE TABLE translations (
id SERIAL NOT NULL,
KEY VARCHAR(255),
LANGUAGE VARCHAR(255),
TRANSLATION VARCHAR(255)
)
我有一个用于进行查询的自定义 JPA 对象:
@PostConstruct
public void loadData() {
td = new TData();
String query = "SELECT c FROM Translations c WHERE c.Id = '70'";
//String query = "SELECT p from translations p where id=70";
td = (TData) dao.jpqlQuerySingle(query);
}
当我打开 JSF 页面时,Java 对象是空的。Java 方法jpqlQuerySingle
用于将结果作为对象返回,但由于某种原因,我得到了空对象。你能帮我解决这个问题吗?