Announcement Announcement Module
Collapse
No announcement yet.
object is an unsaved transient instance error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • object is an unsaved transient instance error

    Hi,

    I have problems persisting an object with hibernate in a webflow application:

    The object has a one-to-one mapping:

    Code:
    class Main {
    ...
    @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    public Global getGlobal() {
      return this.global;
    }
    ...
    }
    I am using this method to save the object (in a DAO)

    Code:
    ...
    public Main save(Main object) {
      return (Main) hibernateTemplate.merge(object);
    }
    ...
    My transaction setup is as follows:

    Code:
    ...
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
      <tx:attributes>
        <tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
        <tx:method name="save*" read-only="false" propagation="REQUIRED"/>
      </tx:attributes>
    </tx:advice>
    
    <aop:config>
      <aop:advisor id="managerTX" advice-ref="txAdvice" pointcut="execution(* *..service.*Manager.*(..))"/>
    </aop:config>
    ...
    But everytime I try to save the object I get this error:
    Code:
    Caused by: org.hibernate.TransientObjectException: object is an unsaved transient instance - save the transient instance before merging: lu.bce.movie2me.web.model.Global
    	at org.hibernate.event.def.DefaultMergeEventListener.getTransientCopyCache(DefaultMergeEventListener.java:128)
    	at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:90)
    	at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:705)
    	at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:689)
    	at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:693)
    	at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:827)
    	at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
    	... 139 more
    Any hints and advice would be appreciated. Thanks!

  • #2
    Read the api and pay attention to the difference between save() and merge().

    Comment

    Working...
    X