我的 Spring-3.0.5/Hibernate-3.3.0 webapp 不存储集合。当创建一个带有关联集合的新持久化对象时,该对象会被持久化,但集合不会。在测试用例中一切正常,所以它不是错误的映射注释。
当我使用日志级别 TRACE 运行测试用例和 webapp 时,测试用例会产生类似 (grep for "[fF]lush":
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
但 webapp 只说:
org.hibernate.impl.SessionImpl - setting flush mode to: MANUAL
当我抓住 vor "SessionImpl" 我得到
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
对于测试用例和
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
对于网络应用程序。
我不知道,为什么 webapp 总是禁用自动刷新!
这是我的 Webapp-Configuration(为清楚起见的缩写):
<tx:annotation-driven proxy-target-class="true"/>
<context:spring-configured/>
<context:component-scan base-package="de.halbekunst.fotos" />
<mvc:annotation-driven />
和我的资源定义:
<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>