My Spring-3.0.5 / Hibernate-3.3.0 webapp不存储集合。使用asscociated集合创建新的persitent对象时,该对象将被持久化,但该集合不会被持久化。在一个测试用例中,一切都运行良好,因此它不是一个错误的Mapping-Annotation。
当我运行测试用例和带有日志级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总是禁用自动刷新!
这是我的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>
答案 0 :(得分:2)
经过一周的调试(我将原始项目划分到我能够识别所描述错误的来源之后),我现在知道出了什么问题:
故障控制器的暴露方法不公开,因此,注释没有效果。
对于有类似问题的任何人:这是我的项目的简化版本,它证明了错误:
https://github.com/kai-moritz/experiment
你需要Maven! 要运行该示例,只需执行两个命令
mvn war:inpace
mvn jetty:run