我的項目最初開發時使用了與持久性單元和項目是spring,Struts2的hibernate集成一體。現在我需要使用jboss連接池和持久性單元。 任何人都可以讓我以最短的方式轉換項目中的那個需求。 當前spring.xmlSpring與jboss的持久化單元
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>properties/database.properties</value>
</property>
</bean>
<bean id="springdatasource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="springdatasource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>model.AtOrganisation</value>
<value>model.AtDivision</value>
</list>
</property>
</bean>
<bean id="orgdao" class="dao.OrganisationDaoImp">
<property name="sessionfactory" ref="sessionFactory" />
</bean>
<bean id="divdao" class="dao.DevisionDaoImpl">
<property name="sessionfactory" ref="sessionFactory" />
</bean>
<bean id="empAction" class="action.OraganisationAction">
<property name="orgdao" ref="orgdao" />
</bean>
<bean id="empAction2" class="action.DevisionAction">
<property name="orgdao" ref="orgdao" />
</bean>
<bean id="divAction" class="action.DevisionAction">
<property name="divdao" ref="divdao" />
</bean>
樣品DAO類
public class DevisionDaoImpl implements DevisionDao {
private SessionFactory sessionfactory;
public void setSessionfactory(SessionFactory sessionfactory) {
this.sessionfactory = sessionfactory;
}
@Override
public List showDiv() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addDiv(AtDivision div) {
Session session = sessionfactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(div);
tx.commit();
//System.out.println("after save : " + org.getAoId());
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
e.printStackTrace();
} finally {
session.close();
}
}
}
我相信,你只需要切換到JBoss的數據源,是嗎? –
是的,我需要通過container.not來管理事務,而不是像我當前的代碼。 – Dilis