<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="oracledatasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" /> <property name="username" value="music" /> <property name="password" value="music" /> </bean> <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="oracledatasource"/> <property name="mappingResources"> <list> <value>song.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.OracleDialect </value> </property> </bean> <bean id="songsbean" class="spring.SongsManagement"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> </beans>
package spring; import entities.Song; import java.util.List; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class SongsManagement extends HibernateDaoSupport { public void addSong(String title, String singer ){ Song s = new Song(); s.setTitle(title); s.setSinger(singer); this.getHibernateTemplate().save(s); } public List getSongs() { return (List) this.getHibernateTemplate().find("from Song"); } }