public List<GoodsName> queryForPage(final String hql, final int offset,
final int length) {
// TODO Auto-generated method stub
List<GoodsName> list = getHibernateTemplate().executeFind(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
query.setFirstResult(offset);
query.setMaxResults(length);
List list = query.list();
return list;
}
});
return list;
}
我想问一下.上面的session是什么时候被赋值的...是怎么赋值的
解决方案 »
- Spring+Hibernate能自动创建表,但之后程序中无法用HibernateTemplate访问
- 抽象类、接口作为方法参数 java 反射 (只有这点分了。。。)
- java 异常处理通用类
- 手机EDGE上网的问题
- 怎么把String类型的一和①区分开呢 大家请指教 谢!
- 在struts+spring+hibernate得技术框架下应用jboss的数据源的困惑
- iframe内嵌页面取不到struts变量值
- hibernate 父子关系 新增 父表 时 子表 出现的问题?
- 没有这个包,到哪去下?
- 怎样在xsl文件中使用+、-、*、/、%等运算????请举些例子。
- spring.net 属性切入点配置问题
- hibernate支持第三方事务吗
是外面传进来的
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;public class TestH extends HibernateDaoSupport {
public void SayHello(){
this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session arg0)
throws HibernateException, SQLException {
// TODO Auto-generated method stub
return null;
}});
}
}
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/ssh2/bean/Classes.hbm.xml</value>
<value>org/ssh2/bean/Student.hbm.xml</value>
</list>
</property>
</bean>
Object result = execute(action, isExposeNativeSession());
if (result != null && !(result instanceof List)) {
throw new InvalidDataAccessApiUsageException(
"Result object returned from HibernateCallback isn't a List: [" + result + "]");
}
return (List) result;
}public Object execute(HibernateCallback action, boolean exposeNativeSession) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null"); Session session = getSession();
boolean existingTransaction = SessionFactoryUtils.isSessionTransactional(session, getSessionFactory());
if (existingTransaction) {
logger.debug("Found thread-bound Session for HibernateTemplate");
} FlushMode previousFlushMode = null;
try {
previousFlushMode = applyFlushMode(session, existingTransaction);
enableFilters(session);
Session sessionToExpose = (exposeNativeSession ? session : createSessionProxy(session));
Object result = action.doInHibernate(sessionToExpose);
flushIfNecessary(session, existingTransaction);
return result;
}
catch (HibernateException ex) {
throw convertHibernateAccessException(ex);
}
catch (SQLException ex) {
throw convertJdbcAccessException(ex);
}
catch (RuntimeException ex) {
// Callback code threw application exception...
throw ex;
}
finally {
if (existingTransaction) {
logger.debug("Not closing pre-bound Hibernate Session after HibernateTemplate");
disableFilters(session);
if (previousFlushMode != null) {
session.setFlushMode(previousFlushMode);
}
}
else {
// Never use deferred close for an explicitly new Session.
if (isAlwaysUseNewSession()) {
SessionFactoryUtils.closeSession(session);
}
else {
SessionFactoryUtils.closeSessionOrRegisterDeferredClose(session, getSessionFactory());
}
}
}
}
可不是我们JAVA类里面的session啊。
像
<property name="sessionFactory">
</property>
这些
容器启动运行起来的时候就会给配置好这些属性的类注入的