gpt4 book ai didi

mysql - 我的查询返回一个空列表而不是一个条目

转载 作者:行者123 更新时间:2023-11-29 06:59:00 26 4
gpt4 key购买 nike

我正在尝试从表中获取我的用户: enter image description here

我通过表单保存了这些值(因此辣椒配置似乎不错)。

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。

enter image description here该值不应为 null,而应为一个值(测试用户)。

我做错了什么?

谢谢

最佳答案

卡宴回归的原因null而不是对象的是 PK 字段在结果集中找不到或其值为 NULL 。在你的情况下,我认为 Cayenne 在结果中找不到 PK,因为它似乎被定义为 userid id DB 并在 Cayenne 代码中我看到它是 USERID .

请让我为您提供一些有关您的代码的一般建议。每个请求创建 ServerRuntime 并不是真正有效的解决方案,您应该将其保留为应用程序单例,请参阅 this question了解详情。而且ObjectSelect (或者 SelectQuery 如果您使用旧版本的 Cayenne)是选择对象的更好(而且确实更灵活)的方式。

你可以像这样使用它:

List<UserInfoFactory> result = ObjectSelect.query(UserInfoFactory.class)
.select(context);

关于mysql - 我的查询返回一个空列表而不是一个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44306272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com