所以我有这个查询
private static final String GET_LOCK_HISTORY1 = "select lh from UserLockHistoryEntity lh ";
使用此代码执行
List<UserLockHistoryEntity> result = getQuery(GET_LOCK_HISTORY1).list();
这将返回一个空数组。在控制台上,我得到生成的SQL
select
userlockhi0_.USER_LOCK_HISTORY_ID as USER_LOC1_15_,
userlockhi0_.LOCK_TYPE as LOCK_TYP2_15_,
userlockhi0_.TIMESTAMP as TIMESTAM3_15_,
userlockhi0_.LOCKED_USER_ID as LOCKED_U4_15_,
userlockhi0_.COMPANY_ID as COMPANY_5_15_,
userlockhi0_.PARTNER_ID as PARTNER_6_15_,
userlockhi0_.IP_ORIGIN as IP_ORIGI7_15_,
userlockhi0_.LOCKED_BY_USER as LOCKED_B8_15_,
userlockhi0_.LOCKED_BY_TYPE as LOCKED_B9_15_,
userlockhi0_.LOCK_REASON as LOCK_RE10_15_
from
ONCPRTDEV.USER_LOCK_HISTORY userlockhi0_
我将它粘贴在SQL开发人员上,后者返回8行(所有表记录)
Bellow它是我的映射文件
<?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 Jan 22, 2014 3:07:58 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="pt.vdf.onc.core.business.entity.user.UserLockHistoryEntity" table="USER_LOCK_HISTORY">
<id name="id" type="java.lang.Long">
<column name="USER_LOCK_HISTORY_ID" />
<generator class="assigned" />
</id>
<property name="lockType">
<column name="LOCK_TYPE" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">pt.vdf.onc.core.common.type.user.UserLockType</param>
</type>
</property>
<property name="timestamp" type="java.lang.String">
<column name="TIMESTAMP" />
</property>
<property name="userId" type="java.lang.Long">
<column name="LOCKED_USER_ID" />
</property>
<property name="companyId" type="java.lang.Long">
<column name="COMPANY_ID" />
</property>
<property name="partnerId" type="java.lang.Long">
<column name="PARTNER_ID" />
</property>
<property name="ipOrigin" type="java.lang.String">
<column name="IP_ORIGIN" />
</property>
<property name="lockedByUser" type="java.lang.Long">
<column name="LOCKED_BY_USER" />
</property>
<property name="lockedByType">
<column name="LOCKED_BY_TYPE" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">pt.vdf.onc.core.common.type.user.UserLockByType</param>
</type>
</property>
<property name="lockedReason">
<column name="LOCK_REASON" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">pt.vdf.onc.core.common.type.user.UserLockReason</param>
</type>
</property>
</class>
</hibernate-mapping>
和实体
public class UserLockHistoryEntity implements java.io.Serializable {
private Long id;
private UserLockType lockType;
private String timestamp;
private Long userId;
private Long companyId;
private Long partnerId;
private String ipOrigin;
private Long lockedByUser;
private UserLockByType lockedByType;
private UserLockReason lockedReason;
//getters and setters here (removed them for simplicity)
}
表格定义:
USER_LOCK_HISTORY_ID NUMBER(38,0)
LOCK_TYPE NUMBER(38,0)
TIMESTAMP DATE
LOCKED_USER_ID NUMBER(38,0)
COMPANY_ID NUMBER(38,0)
PARTNER_ID NUMBER(38,0)
IP_ORIGIN VARCHAR2(30 BYTE)
LOCKED_BY_USER VARCHAR2(50 BYTE)
LOCK_REASON NUMBER(38,0)
LOCKED_BY_TYPE NUMBER
以某些行为例:
809 0 14.01.22 5003953 1003739 0 127.0.0.1 5003953 2 0
810 0 14.01.22 5003953 1003739 0 127.0.0.1 5003953 2 0
811 0 14.01.22 2054497 621936 0 127.0.0.1 2054497 2 0
当查询在SQL Developer上完美运行时,为什么我得到一个空结果列表?谢谢你的帮助
答案 0 :(得分:2)
有关
List<UserLockHistoryEntity> result = getQuery(GET_LOCK_HISTORY1).list();
有效查询
select lh from UserLockHistoryEntity lh
查询
select lh.id from UserLockHistoryEntity lh
有效结果是:
List<Long> result = getQuery(GET_LOCK_HISTORY1).list();
答案 1 :(得分:0)
你的pojo是如何注释的? id字段是否注释为id?
public class UserLockHistoryEntity implements java.io.Serializable {
private Long id;
...
@Id
@Column(name = "USER_LOCK_HISTORY_ID", unique = true, nullable = false)
public Long getId() {
return this.id;
}
...
}