用datediff(day,time1,time2)方法

package test;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.factory.HibernateSessionFactory;

public class QueryTest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session = HibernateSessionFactory.getSession();
        Transaction tx = session.beginTransaction();
        Manage m = null;
        try{
        Query q = session.createQuery(" from Manage m where datediff(day,m.loadTime,getdate())=0");
        List list = q.list();
        tx.commit();
        for(int i=0;i<list.size();i++){
        m = (Manage)list.get(i);
        System.out.print("adminId="+m.getId().getAdminId()+",adminName="+m.getId().getAdminName());
        System.out.println(",adminPass="+m.getId().getAdminPass()+",loadTime="+m.getId().getLoadTime());
        System.out.println("------------------------------------------------------");
        }
        }catch(Exception e){
        e.printStackTrace();
        }finally{
        session.close();
        }

}

}

hql 应用中的问题

你可能感兴趣的:(Hibernate)