2013-03-04 75 views
1

我有简单的Spring MVC - Hibernate应用程序,在连接到MySQL 5.5数据库时工作正常(插入&读取数据)。在将相同的应用程序连接到Oracle 10g时,它从数据库中读取记录,但无法插入记录。休眠会话模式默认设置为手动

在调试时,我发现会话的flushMode是MANUAL。保存记录后,我明确写了session.flush(),并且代码在两个数据库中都开始正常工作。

我的问题 - 当我从休眠的documentation理解,默认刷新模式为自动。我没有在我的代码中将它设置为手动,但不知何故它已经设置好了。如何控制这个?

我使用Spring 3.1.1和Hibernate 3.5.6。以下是我的root-context.xml和servlet-context.xml文件。

的servlet-context.xml中:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
    <property name="prefix" value="/WEB-INF/views/"/> 
    <property name="suffix" value=".jsp"/> 
</bean> 

<context:component-scan base-package="com.home.cfs"/> 

<mvc:annotation-driven/> 

根context.xml中:

<bean id="databaseDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <!-- 
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> 
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:testdb"/> 
    <property name="username" value="test_usr"/> 
    <property name="password" value="test_usr"/> 
    --> 

    <property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
    <property name="url" value="jdbc:mysql://localhost:3306/person"/> 
    <property name="username" value="root"/> 
    <property name="password" value="admin"/> 

</bean> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource" ref="databaseDataSource"/> 
    <property name="packagesToScan" value="com.home.cfs"/> 
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/> 
    <property name="hibernateProperties"> 
     <props> 
      <!-- <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> --> 
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> 
      <prop key="hibernate.show_sql">true</prop> 
      <prop key="hibernate.format_sql">true</prop> 
      <prop key="hibernate.use_sql_comments">true</prop> 
      <prop key="hibernate.hbm2ddl.auto">update</prop> 
     </props> 
    </property> 
</bean> 

<tx:annotation-driven/> 
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory"/> 
</bean> 

请让我知道,如果需要更多的细节。

谢谢。

回答

0

检查您是否打开了OpenSessionInViewFilter过滤器。这似乎是这个可能的罪魁祸首。