Test2 userLoadedFromDB;
PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory
.getBean("PersistenceLayer");
Test2 test2 = new Test2();
test2.setId(new Integer(33));
test2.setName("Adi");
/* 4. Save the new user to the database */
persistenceLayer.addTest2DAO(test2);
userLoadedFromDB = persistenceLayer.findTest2DAO(new Integer(11));
System.out.println("User Loaded from DB Name="+ userLoadedFromDB.getName());
/* Update the user */
userLoadedFromDB.setName("Gill");
userLoadedFromDB.setId(new Integer(14));
persistenceLayer.updateTest2DAO(userLoadedFromDB);
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/games
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">
MySql Connector 5.1.7
</property>
<property name="connection.password">titi</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="pool_size">12</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/b ... ns-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation"
value="file:src/hibernate.cfg.xml">
</property>
<property name="annotatedClasses">
<list>
<value>snir.test.hibernatespring.Test2</value></list>
</property></bean>
<bean id="Test2DAO" class="snir.test.hibernatespring.Test2DAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PersistenceLayer"
class="snir.test.hibernatespring.PersistenceLayer" abstract="false"
lazy-init="default" autowire="default" dependency-check="default">
<property name="test2DAO">
<ref bean="Test2DAO" />
</property>
</bean></beans>
[/u]