Results 1 to 2 of 2

Thread: object is an unsaved transient instance error

  1. #1
    Join Date
    May 2008
    Posts
    17

    Question 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. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •