我有以下我在hibernate中使用的查询
select a.*, b.cur_date, c.value as maxloginattempts
from tbl_user a, tbl_eod_bod_stat b, tbl_settings c
where upper(a.id) = 'ADMIN'
and usr_status in ('A','E','O','P','U','G','M','D','T') and c.attribute = 'MAX_LOGIN_ATTEMPTS'";
我的主要课程: -
package foo;
import java.sql.Date;
import java.util.Arrays;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;
import com.imageinfo.eclear.hbm.pojo.TblUser;
public class myclass {
static SessionFactory factory;
public static void main(String[] args) {
myclass obj=new myclass();
System.out.println("above buildfactory");
try{
factory=new Configuration().configure().buildSessionFactory();
}catch(Exception e)
{
e.printStackTrace();
}
System.out.println("after buidl");
//obj.raiseEmailNotification();
//obj.doAfter();
//obj.validateInput();
obj.checkPass();
}
public void checkPass(){
String username="S5626";
Session session =factory.openSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery("select a.id,b.id,c.value as maxloginattempts from TblUser a,TblEodBodStat b,TblSettings c where upper(a.id.id)='ADMIN' and c.attribute='MAX_LOGIN_ATTEMPTS'");
//query.setParameter("username", username);
//List list=query.list();
System.out.println("worked");
int i=0;
List list=query.list();
if(!list.isEmpty())
{
for(Object a:list)
{
Object[] o=(Object[])a;
System.out.println(o[0]);
System.out.println(Arrays.toString(o));
}
}
当我运行它时,tblUser对象返回null。
输出
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
after buidl
worked
null
[null, com.imageinfo.eclear.hbm.pojo.TblEodBodStatId@257db8ef, 3]
tblUser.hbm.xml: -
<?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 Dec 3, 2015 4:43:35 PM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="com.imageinfo.eclear.hbm.pojo.TblUser" table="TBL_USER">
<composite-id name="id" class="com.imageinfo.eclear.hbm.pojo.TblUserId">
<key-property name="id" type="string">
<column name="ID" length="22" />
</key-property>
<key-property name="roleId" type="string">
<column name="ROLE_ID" length="3" />
</key-property>
<key-property name="fname" type="string">
<column name="FNAME" length="60" />
</key-property>
<key-property name="emailId" type="string">
<column name="EMAIL_ID" length="100" />
</key-property>
<key-property name="branchCode" type="string">
<column name="BRANCH_CODE" length="5" />
</key-property>
<key-property name="employeeCode" type="string">
<column name="EMPLOYEE_CODE" length="20" />
</key-property>
<key-property name="departmentCode" type="string">
<column name="DEPARTMENT_CODE" length="10" />
</key-property>
<key-property name="userCategory" type="string">
<column name="USER_CATEGORY" length="1" />
</key-property>
<key-property name="description" type="string">
<column name="DESCRIPTION" length="100" />
</key-property>
<key-property name="loggedStatus" type="java.lang.Byte">
<column name="LOGGED_STATUS" precision="2" scale="0" />
</key-property>
<key-property name="lastLogged" type="timestamp">
<column name="LAST_LOGGED" />
</key-property>
<key-property name="currentSessionId" type="string">
<column name="CURRENT_SESSION_ID" length="34" />
</key-property>
<key-property name="currentAttempts" type="java.lang.Boolean">
<column name="CURRENT_ATTEMPTS" precision="1" scale="0" />
</key-property>
<key-property name="expiryDate" type="date">
<column name="EXPIRY_DATE" length="7" />
</key-property>
<key-property name="expireStatus" type="string">
<column name="EXPIRE_STATUS" length="3" />
</key-property>
<key-property name="allowedForms" type="string">
<column name="ALLOWED_FORMS" length="1000" />
</key-property>
<key-property name="groupId" type="string">
<column name="GROUP_ID" length="50" />
</key-property>
<key-property name="usrActiveStatus" type="string">
<column name="USR_ACTIVE_STATUS" length="1" />
</key-property>
<key-property name="usrStatus" type="string">
<column name="USR_STATUS" length="1" />
</key-property>
<key-property name="idmsStatus" type="string">
<column name="IDMS_STATUS" length="1" />
</key-property>
<key-property name="creator" type="string">
<column name="CREATOR" length="22" />
</key-property>
<key-property name="approver" type="string">
<column name="APPROVER" length="22" />
</key-property>
<key-property name="CSessionid" type="string">
<column name="C_SESSIONID" length="34" />
</key-property>
<key-property name="ASessionid" type="string">
<column name="A_SESSIONID" length="34" />
</key-property>
<key-property name="creatorDate" type="timestamp">
<column name="CREATOR_DATE" />
</key-property>
<key-property name="creatorIpAddress" type="string">
<column name="CREATOR_IP_ADDRESS" length="15" />
</key-property>
<key-property name="approverDate" type="timestamp">
<column name="APPROVER_DATE" />
</key-property>
<key-property name="approverIpAddress" type="string">
<column name="APPROVER_IP_ADDRESS" length="15" />
</key-property>
<key-property name="logoutDate" type="timestamp">
<column name="LOGOUT_DATE" />
</key-property>
<key-property name="lockedStatus" type="string">
<column name="LOCKED_STATUS" length="1" />
</key-property>
<key-property name="userIdentity" type="string">
<column name="USER_IDENTITY" length="20" />
</key-property>
<key-property name="passwd" type="string">
<column name="PASSWD" length="50" />
</key-property>
<key-property name="passHist1" type="string">
<column name="PASS_HIST1" length="50" />
</key-property>
<key-property name="passHist2" type="string">
<column name="PASS_HIST2" length="50" />
</key-property>
<key-property name="passHist3" type="string">
<column name="PASS_HIST3" length="50" />
</key-property>
<key-property name="passHist4" type="string">
<column name="PASS_HIST4" length="50" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
TblUserId.java
package com.imageinfo.eclear.hbm.pojo;
// Generated Dec 3, 2015 4:43:34 PM by Hibernate Tools 3.2.4.GA
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
/**
* TblUserId generated by hbm2java
*/
public class TblUserId implements java.io.Serializable {
private String id;
private String roleId;
private String fname;
private String emailId;
private String branchCode;
private String employeeCode;
private String departmentCode;
private String userCategory;
private String description;
private Byte loggedStatus;
private Timestamp lastLogged;
private String currentSessionId;
private Boolean currentAttempts;
private Date expiryDate;
private String expireStatus;
private String allowedForms;
private String groupId;
private String usrActiveStatus;
private String usrStatus;
private String idmsStatus;
private String creator;
private String approver;
private String CSessionid;
private String ASessionid;
private Timestamp creatorDate;
private String creatorIpAddress;
private Timestamp approverDate;
private String approverIpAddress;
private Timestamp logoutDate;
private String lockedStatus;
private String userIdentity;
private String passwd;
private String passHist1;
private String passHist2;
private String passHist3;
private String passHist4;
public TblUserId() {
}
public TblUserId(String id, String roleId, String fname, String emailId,
String branchCode, String employeeCode, String departmentCode,
String userCategory, String description, Byte loggedStatus,
Timestamp lastLogged, String currentSessionId,
Boolean currentAttempts, Date expiryDate, String expireStatus,
String allowedForms, String groupId, String usrActiveStatus,
String usrStatus, String idmsStatus, String creator,
String approver, String CSessionid, String ASessionid,
Timestamp creatorDate, String creatorIpAddress,
Timestamp approverDate, String approverIpAddress,
Timestamp logoutDate, String lockedStatus, String userIdentity,
String passwd, String passHist1, String passHist2,
String passHist3, String passHist4) {
this.id = id;
this.roleId = roleId;
this.fname = fname;
this.emailId = emailId;
this.branchCode = branchCode;
this.employeeCode = employeeCode;
this.departmentCode = departmentCode;
this.userCategory = userCategory;
this.description = description;
this.loggedStatus = loggedStatus;
this.lastLogged = lastLogged;
this.currentSessionId = currentSessionId;
this.currentAttempts = currentAttempts;
this.expiryDate = expiryDate;
this.expireStatus = expireStatus;
this.allowedForms = allowedForms;
this.groupId = groupId;
this.usrActiveStatus = usrActiveStatus;
this.usrStatus = usrStatus;
this.idmsStatus = idmsStatus;
this.creator = creator;
this.approver = approver;
this.CSessionid = CSessionid;
this.ASessionid = ASessionid;
this.creatorDate = creatorDate;
this.creatorIpAddress = creatorIpAddress;
this.approverDate = approverDate;
this.approverIpAddress = approverIpAddress;
this.logoutDate = logoutDate;
this.lockedStatus = lockedStatus;
this.userIdentity = userIdentity;
this.passwd = passwd;
this.passHist1 = passHist1;
this.passHist2 = passHist2;
this.passHist3 = passHist3;
this.passHist4 = passHist4;
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getRoleId() {
return this.roleId;
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getFname() {
return this.fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getEmailId() {
return this.emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getBranchCode() {
return this.branchCode;
}
public void setBranchCode(String branchCode) {
this.branchCode = branchCode;
}
public String getEmployeeCode() {
return this.employeeCode;
}
public void setEmployeeCode(String employeeCode) {
this.employeeCode = employeeCode;
}
public String getDepartmentCode() {
return this.departmentCode;
}
public void setDepartmentCode(String departmentCode) {
this.departmentCode = departmentCode;
}
public String getUserCategory() {
return this.userCategory;
}
public void setUserCategory(String userCategory) {
this.userCategory = userCategory;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public Byte getLoggedStatus() {
return this.loggedStatus;
}
public void setLoggedStatus(Byte loggedStatus) {
this.loggedStatus = loggedStatus;
}
public Timestamp getLastLogged() {
return this.lastLogged;
}
public void setLastLogged(Timestamp lastLogged) {
this.lastLogged = lastLogged;
}
public String getCurrentSessionId() {
return this.currentSessionId;
}
public void setCurrentSessionId(String currentSessionId) {
this.currentSessionId = currentSessionId;
}
public Boolean getCurrentAttempts() {
return this.currentAttempts;
}
public void setCurrentAttempts(Boolean currentAttempts) {
this.currentAttempts = currentAttempts;
}
public Date getExpiryDate() {
return this.expiryDate;
}
public void setExpiryDate(Date expiryDate) {
this.expiryDate = expiryDate;
}
public String getExpireStatus() {
return this.expireStatus;
}
public void setExpireStatus(String expireStatus) {
this.expireStatus = expireStatus;
}
public String getAllowedForms() {
return this.allowedForms;
}
public void setAllowedForms(String allowedForms) {
this.allowedForms = allowedForms;
}
public String getGroupId() {
return this.groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getUsrActiveStatus() {
return this.usrActiveStatus;
}
public void setUsrActiveStatus(String usrActiveStatus) {
this.usrActiveStatus = usrActiveStatus;
}
public String getUsrStatus() {
return this.usrStatus;
}
public void setUsrStatus(String usrStatus) {
this.usrStatus = usrStatus;
}
public String getIdmsStatus() {
return this.idmsStatus;
}
public void setIdmsStatus(String idmsStatus) {
this.idmsStatus = idmsStatus;
}
public String getCreator() {
return this.creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public String getApprover() {
return this.approver;
}
public void setApprover(String approver) {
this.approver = approver;
}
public String getCSessionid() {
return this.CSessionid;
}
public void setCSessionid(String CSessionid) {
this.CSessionid = CSessionid;
}
public String getASessionid() {
return this.ASessionid;
}
public void setASessionid(String ASessionid) {
this.ASessionid = ASessionid;
}
public Timestamp getCreatorDate() {
return this.creatorDate;
}
public void setCreatorDate(Timestamp creatorDate) {
this.creatorDate = creatorDate;
}
public String getCreatorIpAddress() {
return this.creatorIpAddress;
}
public void setCreatorIpAddress(String creatorIpAddress) {
this.creatorIpAddress = creatorIpAddress;
}
public Timestamp getApproverDate() {
return this.approverDate;
}
public void setApproverDate(Timestamp approverDate) {
this.approverDate = approverDate;
}
public String getApproverIpAddress() {
return this.approverIpAddress;
}
public void setApproverIpAddress(String approverIpAddress) {
this.approverIpAddress = approverIpAddress;
}
public Timestamp getLogoutDate() {
return this.logoutDate;
}
public void setLogoutDate(Timestamp logoutDate) {
this.logoutDate = logoutDate;
}
public String getLockedStatus() {
return this.lockedStatus;
}
public void setLockedStatus(String lockedStatus) {
this.lockedStatus = lockedStatus;
}
public String getUserIdentity() {
return this.userIdentity;
}
public void setUserIdentity(String userIdentity) {
this.userIdentity = userIdentity;
}
public String getPasswd() {
return this.passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getPassHist1() {
return this.passHist1;
}
public void setPassHist1(String passHist1) {
this.passHist1 = passHist1;
}
public String getPassHist2() {
return this.passHist2;
}
public void setPassHist2(String passHist2) {
this.passHist2 = passHist2;
}
public String getPassHist3() {
return this.passHist3;
}
public void setPassHist3(String passHist3) {
this.passHist3 = passHist3;
}
public String getPassHist4() {
return this.passHist4;
}
public void setPassHist4(String passHist4) {
this.passHist4 = passHist4;
}
));
result = 37 * result
+ (getPasswd() == null ? 0 : this.getPasswd().hashCode());
result = 37 * result
+ (getPassHist1() == null ? 0 : this.getPassHist1().hashCode());
result = 37 * result
+ (getPassHist2() == null ? 0 : this.getPassHist2().hashCode());
result = 37 * result
+ (getPassHist3() == null ? 0 : this.getPassHist3().hashCode());
result = 37 * result
+ (getPassHist4() == null ? 0 : this.getPassHist4().hashCode());
return result;
}
}
请注意我在timestamp数据类型的tblUser中有几列。它们在自动生成的hbm.xml中映射,并自动生成pojo作为Serializable,因此我得到了“无法反序列化错误& #39; .later修复我用timestamp手动替换它和用java.sql.Timestamp替换pojos。我使用的是jdk 6。 我有两个疑问: -
1.可能的原因是什么?
2.为什么创建工厂对象需要花费大约20秒的时间。
谢谢
P.S
我跳过发布TblUser.java,它只有一个属性,一个TbluserId类的对象。
答案 0 :(得分:0)
您是否可以检查java代码中存在的查询,其中有一个字段Player[] p = Stream.generate(Player::new).limit(3).toArray(Player[]::new);
被调用。这一定是问题所在。