gpt4 book ai didi

java - 无法使用 hibernate 将数据库中的数据填充到正确的列表对象中

转载 作者:行者123 更新时间:2023-12-01 13:37:08 26 4
gpt4 key购买 nike

我有一个像这样的数据库表:

gid     varchar     not null    primary key
cId varchar not null
guid varchar
d_flag int not null
c_dt datetime
u_dt datetime
d_dt datetime

现在我想通过hibernate获取gid、cid guid和c_dt。

我已经像这样配置了我的映射文件:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 20 Julai 2010 11:40:18 AM by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
<class name="kmbt.csa.sboxm.model.SBoxInfo"
table="gwinfo" >
<id name="id" type="org.hibernate.type.StringType" column="gid">
<generator class="assigned"/>
</id>

<property name="regTime" type="org.hibernate.type.TimestampType">
<column name="c_dt" length="19" not-null="true" />
</property>

<property name="tenantId" type="org.hibernate.type.StringType">
<column name="cId" length="30" not-null="true" />
</property>

<property name="gId" type="org.hibernate.type.StringType" insert="false" update="false">
<column name="gid" length="100" not-null="true" />
</property>

<property name="gUserId" type="org.hibernate.type.StringType">
<column name="guid" length="100" not-null="true" />
</property>

</class>
</hibernate-mapping>

我的pojo类:

public class SBoxInfo implements Serializable {

private static final long serialVersionUID = -4067221292770891832L;


private int id;
private String regTime;
private String sLabelId;
private String tenantId;
private String gId;
private String status;
private String stateChangedTime;
private String gUserId;





public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getRegTime() {
return regTime;
}

public void setRegTime(String regTime) {
this.regTime = regTime;
}

public String getsLabelId() {
return sLabelId;
}

public void setsLabelId(String sLabelId) {
this.sLabelId = sLabelId;

public String getTenantId() {
return tenantId;
}

public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}

public String getGId() {
return gId;
}

public void setGId(String gId) {
this.gId = gId;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getStateChangedTime() {
return stateChangedTime;
}

public void setStateChangedTime(String stateChangedTime) {
this.stateChangedTime = stateChangedTime;
}

public String getGUserId() {
return gUserId;
}

public void setGUserId(String gUserId) {
this.gUserId = gUserId;
}

}

现在我尝试像这样获取数据:

session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = session.beginTransaction();
Query query = session.createQuery("select regTime,gwId,gwUserId,tenantId from SBoxInfo");
List<SBoxInfo> listOfSaaSGWs = (List<SBoxInfo>)query.list();
transaction.commit();
session.close();

但问题是我无法获取 List SBoxInfo 格式的数据,而是接收简单对象中的数据。

谁能解释一下问题出在哪里吗?

最佳答案

只需将该查询更改为

Query query = session.createQuery("from SBoxInfo");

关于java - 无法使用 hibernate 将数据库中的数据填充到正确的列表对象中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21186906/

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