0
我想從表中得到我的用戶: 我的查詢返回一個空列表,而不是一個條目
我通過表單保存此值(所以卡宴配置似乎也不錯)。
的UserInfoFactory類:
public class UserInfoFactory extends _UserInfo implements Serializable {
private static final long serialVersionUID = 1L;
public static ObjectContext getContext() {
@SuppressWarnings("deprecation")
ServerRuntime runtime = new ServerRuntime("cayenne-myapplication.xml");
return runtime.newContext();
}
@SuppressWarnings("unchecked")
public static List<UserInfoFactory> getUsersInfo() {
SQLTemplate select = new SQLTemplate(UserInfoFactory.class,
"SELECT * FROM mam.userinfo");
return getContext().performQuery(select);
}
}
我_UserInfo類是:
package com.example.myapplication.model;
import org.apache.cayenne.CayenneDataObject;
/**
* Class _UserInfo was generated by Cayenne.
* It is probably a good idea to avoid changing this class manually,
* since it may be overwritten next time code is regenerated.
* If you need to make any customizations, please use subclass.
*/
public abstract class _UserInfo extends CayenneDataObject {
public static final String ADDRESS_PROPERTY = "address";
public static final String EMAIL_PROPERTY = "email";
public static final String FIRSTNAME_PROPERTY = "firstname";
public static final String LASTNAME_PROPERTY = "lastname";
public static final String PHONENUMBER_PROPERTY = "phonenumber";
public static final String USERPASSWORD_PROPERTY = "userpassword";
public static final String USERPRIVILEGES_PROPERTY = "userprivileges";
public static final String USERID_PK_COLUMN = "USERID";
public void setAddress(String address) {
writeProperty(ADDRESS_PROPERTY, address);
}
public String getAddress() {
return (String)readProperty(ADDRESS_PROPERTY);
}
public void setEmail(String email) {
writeProperty(EMAIL_PROPERTY, email);
}
public String getEmail() {
return (String)readProperty(EMAIL_PROPERTY);
}
public void setFirstname(String firstname) {
writeProperty(FIRSTNAME_PROPERTY, firstname);
}
public String getFirstname() {
return (String)readProperty(FIRSTNAME_PROPERTY);
}
public void setLastname(String lastname) {
writeProperty(LASTNAME_PROPERTY, lastname);
}
public String getLastname() {
return (String)readProperty(LASTNAME_PROPERTY);
}
public void setPhonenumber(Integer phonenumber) {
writeProperty(PHONENUMBER_PROPERTY, phonenumber);
}
public Integer getPhonenumber() {
return (Integer)readProperty(PHONENUMBER_PROPERTY);
}
public void setUserpassword(String userpassword) {
writeProperty(USERPASSWORD_PROPERTY, userpassword);
}
public String getUserpassword() {
return (String)readProperty(USERPASSWORD_PROPERTY);
}
public void setUserprivileges(Short userprivileges) {
writeProperty(USERPRIVILEGES_PROPERTY, userprivileges);
}
public Short getUserprivileges() {
return (Short)readProperty(USERPRIVILEGES_PROPERTY);
}
}
我打電話這樣的方法:
List<UserInfoFactory> users = UserInfoFactory.getUsersInfo();
但用戶列表返回NULL 。
我做錯了什麼?
謝謝,
完美!我非常感謝這個決議,我花了太多時間。我期待像'unreconize USERID'之類的錯誤。感謝您的改進。我會盡力去做! – Bob
@FannyV歡迎您!至於'unreconize USERID',這是使用SLQTemplate時遇到的一個問題,它試圖盡力而爲,但默默地失敗。 – Nikita
關於你的好建議的問題(感謝那個,對不起,我需要改進/學習'最佳實踐'):如果我想選擇一個計數(列名),ObjectSelect或SelectQuery是可以的?我應該隨時選擇PK,對吧?在這種情況下,我應該使用SQL模板嗎?我什麼時候可以使用SQL模板? – Bob