Tôi mới trong Hibernate hiện đang muốn triển khai các lớp Mẫu Hibernate, bất kỳ ai vui lòng cho tôi biết về các lớp Mẫu Hibernate.Lớp HibernateTemplate là gì?
tập tin xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/test" />
<property name="username" value="root" />
<property name="password" value="mnrpass" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>employee.hbm.xml</value>
</list>
</property>
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="springHibernateExample" class="com.javarticles.spring.hibernate.SpringHibernateExample">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
HibernateTemplate Spring cung cấp một lớp trừu tượng hơn một phiên Hibernate. Nó chuyển đổi ngoại lệ dành riêng cho Hibernate thành một trong những ngoại lệ truy cập dữ liệu không được kiểm soát của Spring. Nó cũng cung cấp nhiều phương pháp tiện lợi giúp bạn trong việc truy vấn và kiên trì các đối tượng. – Sudhakar