spring - How to use HibernateTemplate? -


i performing retrieval operation list of students database. getting 'empty' data database. used hibernatetemplate in spring hibernate integration,

domain class:-

@entity @table(name="student") public class stdbo { @id private int sno; private string sname,sadd; //setters , getters } 

how can use hibernatecallback() interface search operation? first time integrating spring hibernate, below way correct? tried many ways perform search operations using hibernatetemplate failing details

dao

@repository public class stddao { private hibernatetemplate ht; public void setht(hibernatetemplate ht) {     this.ht = ht; } public list<stdbo> select(){      list<stdbo> list = ht.executefind(new hibernatecallback() {         public object doinhibernate(session ses)                 throws hibernateexception, sqlexception {              criteria criteria=ses.createcriteria(stdbo.class);              system.out.println("before printing sutdents");             list<stdbo> bos = criteria.list();             system.out.println("students are"+bos);//here getting empty list             return bos;         }      });      return list; } 

xml

<bean id="sessionfactory"     class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean">     <property name="datasource" ref="mydatasource" />     <property name="annotatedclasses">         <list>             <value>com.nt.dao.stddao</value>         </list>     </property>     <property name="hibernateproperties">         <props>             <prop key="hibernate.dialect">org.hibernate.dialect.hsqldialect</prop>             <prop key="hibernate.current_session_context_class">thread</prop>         </props>     </property> </bean>  <bean id="template" class="org.springframework.orm.hibernate3.hibernatetemplate">     <property name="sessionfactory" ref="sessionfactory"></property> </bean>  <bean id="dao" class="com.nt.dao.stddao">     <property name="ht" ref="template" /> </bean> 

you need begin (and commit) transaction query data. can manually session.begintransaction() or using @transactional annotation. using @transactional annotation need additional spring configuration: hibernate transaction annotation configuration.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -