我的應用程序是spring,struts2和hibernateand數據庫是postgress 9.2。問題是DAO方法沒有使用flush來提交數據。春季交易中數據未提交到數據庫
我spring.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"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="dao" />
<jee:jndi-lookup id="depo" jndi-name="java:/depo"/>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="depo"/>
<property name="hibernateProperties">
<props>
<!-- <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> -->
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</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>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="orgdao" class="dao.OrganisationDaoImp">
<property name="sessionfactory" ref="sessionFactory" />
</bean>
<bean id="empAction" class="action.OraganisationAction">
<property name="orgdao" ref="orgdao" />
</bean>
我的DAO類是:
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void addOrg(AtOrganisation org) {
Session session = sessionfactory.openSession();
session.saveOrUpdate(org);
//session.flush();
}
任何一個可以指出我錯過了什麼這裏。 注意:如果我取消註釋flush()數據將提交。
你的問題是什麼? –
數據未插入到數據庫中。 我需要做出來調用flush() – Dilis
爲什麼你認爲在事務處於打開狀態時刷新會話? –