HibernateTemplate’s main responsibility is to simplify the work of opening
and closing Hibernate Sessions and to convert Hibernate-specific exceptions
to one of the Spring ORM exceptions
下面实例是按照Spring in action 2nd Edition里面的示例写的。数据库使用Oracle.
1.定义一个POJO
代码如下:
2.创建表
下面就是如何简单的利用Spring 和Hibernate做ORM。
3.定义hibernate配置文件
4.定义数据源
在Spring的配置文件中加入
5.在Spring配置文件中定义LocalSessionFactoryBean
在Spring配置文件中加入
6.定义HibernateTemplate
在Spring配置文件中加入
7.写测试类
以下是HibernateRantDao类的片断
8,在Spring配置文件中加入POJO和测试类
9.运行函数,输入结果