javax.jdo.JDOUserException: 持久化 class "ChatUsers" 在数据库中没有 table
javax.jdo.JDOUserException: Persistent class "ChatUsers" has no table in the database
我正在从 h2 数据库中检索数据。我的问题在 q.setClass()。
在这里,我试图设置 table chatUsers.class,数据库具有相同的 class 但这表明没有 Table ChatUsers。那我能做些什么呢??
如果我不写q.setClass()。然后它正在提供数据,但问题是我无法获得 class.
的列表
聊天用户class
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import java.util.List;
import java.util.Properties;
@PersistenceCapable(detachable="true")
public class ChatUsers {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
int id;
String user;
String mobileNo;
String email;
String password;
public ChatUsers(String user, String password, String mobileNo, String email) {
this.user = user;
this.mobileNo = mobileNo;
this.email = email;
this.password = password;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getMobileNo() {
return mobileNo;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
检索逻辑
public static List<ChatUsers> getAllUsersList() {
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(setProperties());
PersistenceManager pm = pmf.getPersistenceManager();
List<ChatUsers> chatUsersList = null;
pm.currentTransaction().begin();
try {
Query q = pm.newQuery("javax.jdo.query.SQL","SELECT * FROM `CHATUSERS`");
q.setClass(ChatUsers.class);//This line has error
chatUsersList = (List<ChatUsers>) q.execute();
}catch (Exception ex)
{
System.out.println(ex);
}
return chatUsersList;
}
错误代码
javax.jdo.JDOUserException: Persistent class "ChatUsers" has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.
NestedThrowables:
org.datanucleus.store.rdbms.exceptions.NoTableManagedException: Persistent class "ChatUsers" has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.
当您执行() 查询时,您应该改用executeList()。 [1]
另一种解决方案可能是使用 setResultClass() 而不是 setClass()。 [1]
第一个解决方案的示例是:
Query query = pm.newQuery("javax.jdo.query.SQL", "SELECT MY_ID, MY_NAME FROM MYTABLE");
query.setClass(MyClass.class);
List<MyClass> results = query.executeList();
[1]搜索“设置候选项class
" 和 "定义结果类型
" 在文档 URL 中:http://www.datanucleus.org/products/accessplatform/jdo/query.html
我正在从 h2 数据库中检索数据。我的问题在 q.setClass()。 在这里,我试图设置 table chatUsers.class,数据库具有相同的 class 但这表明没有 Table ChatUsers。那我能做些什么呢??
如果我不写q.setClass()。然后它正在提供数据,但问题是我无法获得 class.
的列表聊天用户class
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import java.util.List;
import java.util.Properties;
@PersistenceCapable(detachable="true")
public class ChatUsers {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT)
int id;
String user;
String mobileNo;
String email;
String password;
public ChatUsers(String user, String password, String mobileNo, String email) {
this.user = user;
this.mobileNo = mobileNo;
this.email = email;
this.password = password;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getMobileNo() {
return mobileNo;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
检索逻辑
public static List<ChatUsers> getAllUsersList() {
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(setProperties());
PersistenceManager pm = pmf.getPersistenceManager();
List<ChatUsers> chatUsersList = null;
pm.currentTransaction().begin();
try {
Query q = pm.newQuery("javax.jdo.query.SQL","SELECT * FROM `CHATUSERS`");
q.setClass(ChatUsers.class);//This line has error
chatUsersList = (List<ChatUsers>) q.execute();
}catch (Exception ex)
{
System.out.println(ex);
}
return chatUsersList;
}
错误代码
javax.jdo.JDOUserException: Persistent class "ChatUsers" has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.
NestedThrowables:
org.datanucleus.store.rdbms.exceptions.NoTableManagedException: Persistent class "ChatUsers" has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.
当您执行() 查询时,您应该改用executeList()。 [1]
另一种解决方案可能是使用 setResultClass() 而不是 setClass()。 [1]
第一个解决方案的示例是:
Query query = pm.newQuery("javax.jdo.query.SQL", "SELECT MY_ID, MY_NAME FROM MYTABLE");
query.setClass(MyClass.class);
List<MyClass> results = query.executeList();
[1]搜索“设置候选项class " 和 "定义结果类型 " 在文档 URL 中:http://www.datanucleus.org/products/accessplatform/jdo/query.html