-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to get actual session for H.Template().createCriteria()
PostPosted: Wed Sep 22, 2004 8:04 am 
Newbie

Joined: Tue Apr 13, 2004 4:30 am
Posts: 1
sorry but i cannot find out the right way to get the actual session from Spring:

I'm using a
Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
        <property name="dataSource"><ref bean="dataSource"/></property>
        <property name="mappingResources">
            <list>
....


Method in hibernate-dao:
Quote:
public List getUpdateStatusList(UpdateStatus updateStatus) {
return getHibernateTemplate().createCriteria(sessionFactory ,UpdateStatus.class);

}


how do i call the springfactory-hibernate-session within the createCriteria-method?

Torsten


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 10:38 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
HibernateTemplate in spring 1.1 have public getSessionFactory method and you call
getHibernateTemplate.getSessionFactory()

regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 6:55 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
This is meant to be used in a HibernateCallback (which is stated in the javadoc). For example:

Code:
List result = getHibernateTemplate().executeFind(new HibernateCallback() {
  public Object doInHibernate(Session session) throws HibernateException {
    Criteria criteria = getHibernateTemplate().createCriteria(session, MyClass.class);
    ...
    return criteria.list();
  }
});


Note that the createCriteria call on the template only serves to apply transaction timeout. In every other respect, this is equivalent to:

Code:
List result = getHibernateTemplate().executeFind(new HibernateCallback() {
  public Object doInHibernate(Session session) throws HibernateException {
    Criteria criteria = session.createCriteria(MyClass.class);
    ...
    return criteria.list();
  }
});


In general, if you need any Hibernate functionality that's not covered by HibernateTemplate's convenience operations, simply use a HibernateCallback, which gives you the full power of Hibernate's native API.

Juergen


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.