Announcement Announcement Module
Collapse
No announcement yet.
Collections are not persisted, because Spring sets Hibernate-Flush-Mode to Manual Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Collections are not persisted, because Spring sets Hibernate-Flush-Mode to Manual

    My Spring-3.0.5/Hibernate-3.3.0 webapp does not store collections. When creating a new persitent object with an asscociated collection, the object is persited, but the collection not. In a test-case all works well, so it's not a faulty Mapping-Annotation.

    When I'm running the test-case and the webapp with log-level TRACE, the test-case yields something like (grep for "[fF]lush):

    Code:
    AbstractFlushingEventListener - flushing session
    AbstractFlushingEventListener - processing flush-time cascades
    AbstractFlushingEventListener - dirty checking collections
    AbstractFlushingEventListener - Flushing entities and processing referenced collections
    AbstractFlushingEventListener - Processing unreferenced collections
    AbstractFlushingEventListener - Scheduling collection removes/(re)creates/updates
    AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 0 deletions to 4 objects
    AbstractFlushingEventListener - Flushed: 2 (re)creations, 0 updates, 0 removals to 3 collections
    but the webapp only says:

    Code:
    org.hibernate.impl.SessionImpl - setting flush mode to: MANUAL
    When I grab vor "SessionImpl" I get

    Code:
    DEBUG: org.hibernate.impl.SessionImpl - opened session at timestamp: 13071848978
    DEBUG: org.springframework.orm.hibernate3.HibernateTransactionManager - Opened new Session [org.hibernate.impl.SessionImpl@acaf083] for Hibernate transaction
    DEBUG: org.springframework.orm.hibernate3.HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@acaf083]
    TRACE: org.hibernate.impl.SessionImpl - setting cache mode to: GET
    TRACE: org.hibernate.impl.SessionImpl - setting cache mode to: NORMAL
    TRACE: org.hibernate.impl.SessionImpl - setting cache mode to: GET
    TRACE: org.hibernate.impl.SessionImpl - setting cache mode to: NORMAL
    TRACE: org.hibernate.impl.SessionImpl - after transaction completion
    TRACE: org.hibernate.impl.SessionImpl - closing session
    for the test-case and

    Code:
    DEBUG: org.hibernate.impl.SessionImpl - opened session at timestamp: 13071842364
    TRACE: org.hibernate.impl.SessionImpl - setting flush mode to: MANUAL
    TRACE: org.hibernate.impl.SessionImpl - closing session
    for the webapp.

    I have no clue, why the webapp always disables automatic flushing!

    Here is my Webapp-Configuration (shortend for clearity):
    Code:
    <tx:annotation-driven proxy-target-class="true"/>
    <context:spring-configured/>
    <context:component-scan base-package="de.halbekunst.fotos" />
    <mvc:annotation-driven />
    and my resources-definitions:

    Code:
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
      <property name="driverClass" value="${jdbc.driverClassName}"/>
      <property name="jdbcUrl">
        <value><![CDATA[${jdbc.url}]]></value>
      </property>
      <property name="user" value="${jdbc.username}"/>
      <property name="password" value="${jdbc.password}"/>
      <property name="minPoolSize" value="3"/>
      <property name="maxPoolSize" value="30"/>
      <property name="acquireIncrement" value="3"/>
      <property name="maxIdleTime" value="25200"/>
      <property name="maxIdleTimeExcessConnections" value="14400"/>
      <property name="idleConnectionTestPeriod" value="7200"/>
      <property name="maxStatements" value="50"/>
      <property name="preferredTestQuery" value="SELECT 1;"/>
    </bean>
    
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
      <property name="packagesToScan" value="de.halbekunst.fotos"/>
      <property name="hibernateProperties">
        <value>
          hibernate.dialect=${hibernate.dialect}
          hibernate.query.substitutions=true 'Y', false 'N'
          hibernate.cache.use_second_level_cache=false
          hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
        </value>
        <!-- Turn batching off for better error messages under PostgreSQL -->
        <!-- hibernate.jdbc.batch_size=0 -->
      </property>
    </bean>
        
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    I'm really lost here!

  • #2
    Problem solved!

    After one week of debugging (I striped down my original project until I was able to identify the source of the described error) I now know what went wrong:

    The exposed method of the faulty controller was not public and because of that, the annotation had no effect.

    For anyone, who has similar problems: here is the sriped down version of my project, that demonstrates the error:

    https://github.com/kai-moritz/experiment

    You need Maven.
    To run the example, just execute these two commands:
    mvn war:inplace
    mvn jetty:run
    Last edited by kai.moritz; Jun 13th, 2011, 12:03 PM.

    Comment

    Working...
    X