Java 我的实体没有持久化,但我可以很好地从数据库中读取

Java 我的实体没有持久化,但我可以很好地从数据库中读取,java,spring,hibernate,transient,Java,Spring,Hibernate,Transient,我刚刚更新到Hibernate4.1.5和Spring3.1.2(从2.6ish和2.5或其他版本…)。我已经成功地将所有内容设置为从现有数据库中读取,并且所有页面都显示良好,但是在提交数据时,没有任何内容被持久化到数据库中。我已将日志记录设置为跟踪级别,以尝试跟踪此问题,事务将从我的日志中提取以下15行: DEBUG - org.hibernate.internal.SessionImpl - SessionImpl - Opened session at

我刚刚更新到Hibernate4.1.5和Spring3.1.2(从2.6ish和2.5或其他版本…)。我已经成功地将所有内容设置为从现有数据库中读取,并且所有页面都显示良好,但是在提交数据时,没有任何内容被持久化到数据库中。我已将日志记录设置为跟踪级别,以尝试跟踪此问题,事务将从我的日志中提取以下15行:

DEBUG - org.hibernate.internal.SessionImpl - SessionImpl                    - Opened session at timestamp: 13430582784
TRACE - org.hibernate.internal.SessionImpl - SessionImpl                    - Setting flush mode to: AUTO
TRACE - org.hibernate.internal.SessionImpl - SessionImpl                    - Setting cache mode to: NORMAL
TRACE - org.hibernate.event.internal.AbstractSaveEventListener - AbstractSaveEventListener      - Transient instance of: ic.entities.MyEntity
TRACE - org.hibernate.event.internal.DefaultPersistEventListener - DefaultPersistEventListener    - Saving transient instance
TRACE - org.hibernate.event.internal.AbstractSaveEventListener - AbstractSaveEventListener      - Saving [ic.entities.MyEntity#<null>]
TRACE - org.hibernate.engine.spi.ActionQueue - ActionQueue                    - Adding an EntityIdentityInsertAction for [ic.entities.MyEntity] object
TRACE - org.hibernate.engine.spi.ActionQueue - ActionQueue                    - Adding insert with no non-nullable, transient entities: [EntityIdentityInsertAction[ic.entities.MyEntity#<delayed:0>]]
TRACE - org.hibernate.engine.spi.ActionQueue - ActionQueue                    - Adding resolved non-early insert action.
TRACE - org.hibernate.action.internal.UnresolvedEntityInsertActions - UnresolvedEntityInsertActions  - No unresolved entity inserts that depended on [[ic.entities.MyEntity#<delayed:0>]]
TRACE - org.hibernate.action.internal.UnresolvedEntityInsertActions - UnresolvedEntityInsertActions  - No entity insert actions have non-nullable, transient entity dependencies.
TRACE - org.hibernate.internal.SessionImpl - SessionImpl                    - Closing session
TRACE - org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - LogicalConnectionImpl          - Closing logical connection
TRACE - org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl - JdbcResourceRegistryImpl       - Closing JDBC container [org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl@def577d]
TRACE - org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - LogicalConnectionImpl          - Logical connection closed
并称之为:

@SpringBean MyService myService; //(Using wicket @Springbean)
...
MyEntity entity = new MyEntity();
entity.setEnabled(true);
entity.setNotes("blah");
entity.setSubmittedDate(new Date());
myService.persist(entity);
我将web.xml作为:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>OpenEntityManagerFilter</filter-name>
        <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenEntityManagerFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

上下文配置位置
类路径:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
开放式管理过滤器
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
开放式管理过滤器
/*
最后在applicationContext.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: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.1.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"></bean>

    <tx:annotation-driven/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <context:annotation-config />
    <context:component-scan base-package="ic.services" />
</beans>


再说一次,任何帮助都会很棒。我敢肯定这一定是代表我做的非常愚蠢的事情!:)

尝试将@Transactional添加到持久化服务方法。

太棒了!非常感谢。我在MyServiceImpl类上设置了@Transactional(我忘了提供),但显然这并没有渗透到基类!再次感谢。
@SpringBean MyService myService; //(Using wicket @Springbean)
...
MyEntity entity = new MyEntity();
entity.setEnabled(true);
entity.setNotes("blah");
entity.setSubmittedDate(new Date());
myService.persist(entity);
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>OpenEntityManagerFilter</filter-name>
        <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenEntityManagerFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
<?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: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.1.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"></bean>

    <tx:annotation-driven/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <context:annotation-config />
    <context:component-scan base-package="ic.services" />
</beans>