Announcement Announcement Module
Collapse
No announcement yet.
spring 2.0 m4 0406 JpaDaoSupport + hibernate jpa Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring 2.0 m4 0406 JpaDaoSupport + hibernate jpa

    spring 2.0 m4 0406 JpaDaoSupport +
    hibernate 3.2 rc1+
    hibernate-entitymanager-3.1beta7+
    hibernate-annotations-3.1beta9

    delaying identity-insert due to no transaction in progress why?

    It can't persistence object.
    [org.springframework.orm.jpa.JpaTemplate] - Creating new EntityManager for JPA template execution
    [org.hibernate.impl.SessionImpl] - opened session at timestamp: 4687551353470976
    [org.hibernate.event.def.AbstractSaveEventListener] - transient instance of: com.shenghuotag.pst.User
    [org.hibernate.event.def.DefaultPersistEventListene r] - saving transient instance
    [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.shenghuotag.pst.User#<null>]
    [org.hibernate.event.def.AbstractSaveEventListener] - delaying identity-insert due to no transaction in progress
    [org.springframework.orm.jpa.JpaTemplate] - Closing new EntityManager after JPA template execution
    [org.hibernate.impl.SessionImpl] - closing session
    [org.hibernate.jdbc.ConnectionManager] - connection already null in cleanup : no action


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityMana gerFactoryBean">
    <property name="entityManagerName" value="blog" />
    </bean>

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

    <!-- UserDAO: Hibernate implementation -->
    <bean id="userDAO" class="com.shenghuotag.dao.UserDAO">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    </beans>

  • #2
    Have you tried the hibernate forums? Also note that both hibernate, hibernate jpa support and spring are not final releases - they are beta or milestones.
    Some bugs can be still there.

    Comment


    • #3
      Hi,

      I am encountering the exact same problem.
      "delaying identity-insert due to no transaction in progress"

      So, as a test, in my Daos, I tried, before doing anything, to create a new transaction (tx = entity.getTransaction() ; tx.begin()

      and at the end, tx.commit();
      and it works !

      So, my conclusion is that it is ALWAYS necessary to use transactions with JPA. there is no auto-commit, like we used to have for JDBC...

      If someone can confirm, I would appreciate.

      Regards,
      Sami Dalouche

      Originally posted by zhongwei
      spring 2.0 m4 0406 JpaDaoSupport +
      hibernate 3.2 rc1+
      hibernate-entitymanager-3.1beta7+
      hibernate-annotations-3.1beta9

      delaying identity-insert due to no transaction in progress why?

      It can't persistence object.
      [org.springframework.orm.jpa.JpaTemplate] - Creating new EntityManager for JPA template execution
      [org.hibernate.impl.SessionImpl] - opened session at timestamp: 4687551353470976
      [org.hibernate.event.def.AbstractSaveEventListener] - transient instance of: com.shenghuotag.pst.User
      [org.hibernate.event.def.DefaultPersistEventListene r] - saving transient instance
      [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.shenghuotag.pst.User#<null>]
      [org.hibernate.event.def.AbstractSaveEventListener] - delaying identity-insert due to no transaction in progress
      [org.springframework.orm.jpa.JpaTemplate] - Closing new EntityManager after JPA template execution
      [org.hibernate.impl.SessionImpl] - closing session
      [org.hibernate.jdbc.ConnectionManager] - connection already null in cleanup : no action


      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
      "http://www.springframework.org/dtd/spring-beans.dtd">

      <beans>
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityMana gerFactoryBean">
      <property name="entityManagerName" value="blog" />
      </bean>

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

      <!-- UserDAO: Hibernate implementation -->
      <bean id="userDAO" class="com.shenghuotag.dao.UserDAO">
      <property name="entityManagerFactory" ref="entityManagerFactory"/>
      </bean>

      </beans>

      Comment


      • #4
        This is from the EJB 3 Spec - 5.6.2.1 Application-managed Transaction-scoped Persistence Context

        "If the entity manager is invoked outside the scope of a transaction, a persistence context is created and destroyed to service the method call only, and any entities loaded from the database will immediately become detached at the end of the method call. "

        That's the latest published version, and might very well have been revised since then.

        What is the actual behavior you see without running within a transaction? Do you get the entity persisted or is an exception thrown at some point? The log message seems ok, they are just delaying the id lookup to coincide with the flush is how I would interpret it.

        Comment


        • #5
          Is there actually a problem if the key insert is delyed? that's actually consistent since if you are running inside the transaction and getting the key from the database you can't 'put it back' if the transaction is rolledback. Some users actually had serious problems since under very heavy load the database can waste a lot of keys in some scenarios.
          Handling transactions by yourself is not something recommended - moreover, you code should be independent of flushing or key inserts - it makes it very fragile since these events are related to the database and external factors (like number of queries or internal synchronization) and you can run into subtle issues very easily.

          Comment

          Working...
          X