我们希望使用HQL从Spring和Hibernate的角度获取数据库中的所有记录
但问题在于,如何通过bean类的“applicationContext.xml”文件初始化**org.hibernate.Session se。我们希望使用HQL从Spring和Hibernate的角度获取数据库中的所有记录,spring,hibernate,Spring,Hibernate,但问题在于,如何通过bean类的“applicationContext.xml”文件初始化**org.hibernate.Session se。 Here i tried 2 write cod 2 get list from Mysql Database using spring nd Hibernate. public void getList(**Session se**){ 字符串liststudent=“from StudentList stud”; Query q=se.creat
Here i tried 2 write cod 2 get list from Mysql Database using spring nd Hibernate.
public void getList(**Session se**){
字符串liststudent=“from StudentList stud”;
Query q=se.createQuery(liststudent);
List=q.List();
对于(对象对象:列表){
Object studarr[]=(Object[])obj;
System.out.println(“零索引处的数据”+studarr[0]);
}
}
正如这里所示,属性名**模板**已由ref模板初始化。
是否有任何方法可以初始化会话se。
使用context.xml文件
定义会话工厂
public void getList(**Session se**){
String liststudent="from StudentList stud";
Query q=se.createQuery(liststudent);
List<Object> list=q.list();
for(Object obj:list){
Object studarr[]=(Object[])obj;
System.out.println("Data at Zero Index"+studarr[0]);
}
}
As here property name **template** has been initialized by the ref template.
Is there any way to initialize Session se.
<bean name="mydao" class="dao.MyDao">
<property name="template" ref="template"></property>
</bean>
<bean id="sessionFactory" class="LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!--define other properties...mapping files
</bean>
<bean id="template" class="*HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean name="mydao" class="dao.MyDao">
<property name="template" ref="template"></property>
</bean>