HibernateTemplate Callback 2

package com.bee.common.hibernate.callback;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

/**
 * 查询单项结果
 * 
 * @author Bee
 * 
 * @param <T>
 */
public class SingelResultHibernateCallback<T> implements HibernateCallback<T> {

	String hql;

	public SingelResultHibernateCallback(String hql) {
		this.hql = hql;
	}

	@SuppressWarnings("unchecked")
	public T doInHibernate(Session session) throws HibernateException,
			SQLException {
		Query query = session.createQuery(hql);
		return (T) query.uniqueResult();
	}

}
 

你可能感兴趣的:(HibernateTemplate Callback 2)