String sql="select * from sys_invitation where to_phone = '13000000000' order by create_time desc ;"; Session currentSession = this.getCurrentSession(); List<SysInvitation> list = currentSession.createSQLQuery(sql).addEntity(SysInvitation.class).list(); for(SysInvitation syslist:list){ String invitation_code2 = syslist.getInvitation_code(); System.out.println("invitation_code2:"+invitation_code2); } Object uniqueResult = this.getCurrentSession().createCriteria(SysInvitation.class).add(Restrictions.eq("to_phone", account)).add Order(Order.desc("create_time")).setMaxResults(1).uniqueResult(); if(uniqueResult==null){ return ""; }else { SysInvitation invitation = (SysInvitation) uniqueResult; return invitation.getInvitation_code(); }