hibernate hql拼接语句几种方式,模糊查询

1: OID is param
    String strSQL="from Classes as a where a.classno like :name";    
    Query query = session.createQuery(strSQL);    
    query.setString("name", "%"+OId+"%");    
    List result=query.list();


2: OID is param
    List result=session.createQuery("from Classes as a where a.classno like '%"+OId+"%'").list(); 


3: OID is param
    List result=session.createQuery("from Classes as a where a.classno like :name").setParameter("name",OId).list();



4: DetachedCriteria 的使用
	public FunctionEntity getFunctionEntityById(String id){
		DetachedCriteria criteria = DetachedCriteria.forClass(FunctionEntity.class);
		criteria.add(Restrictions.eq("id", id));
		return (FunctionEntity) getHibernateTemplate().findByCriteria(criteria).get(0);
	}

你可能感兴趣的:(java,Hibernate)