Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我们希望使用HQL从Spring和Hibernate的角度获取数据库中的所有记录_Spring_Hibernate - Fatal编程技术网

我们希望使用HQL从Spring和Hibernate的角度获取数据库中的所有记录

我们希望使用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

但问题在于,如何通过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.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>