Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Template and InvalidDataAccessApiUsageException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Template and InvalidDataAccessApiUsageException

    Hello,

    I am using Hibernate 2.1.6 and Spring 1.1.

    I would like to know to what kind of problem the following exception points at trying to store a class using the Spring Hibernate template.

    I suspect I am missing out on something quite basic, so if you could point me to other posts or documentation that I should read, then that would be great ....

    Code:
    org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.vvdb.bus.rights.Rights
    	org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:464)
    	org.springframework.orm.hibernate.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:554)
    	org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:472)
    	org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:373)
    	org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:241)
    	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:66)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
    	org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)
    	$Proxy0.storeGallery(Unknown Source)
    	com.vvdb.web.gallery.AddGalleryController.onSubmit(AddGalleryController.java:64)
    	org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:223)
    	org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:237)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:121)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:495)
    	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:321)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	com.vvdb.web.gallery.PerformanceLoggingFilter.doFilter(PerformanceLoggingFilter.java:25)
    Class definition:

    Code:
    class Resource {
    
        ...
        private Rights rights;
    }
    Code:
    class Gallery extends Resource{
    ...
    
    }
    Code:
    class HibernateGalleryDao extends HibernateDaoSupport{
     public void create(Gallery gal) throws DataAccessException {
            getHibernateTemplate().saveOrUpdate(gal);
        }
    }

  • #2
    The problem looks hibernate only related. When you define your mapping, you can define behaviour for "cascading" deletes, updates, save, ... In your case you probably don't have the cascading for save which requires you to have all reachable element already manually persisted.
    Have a look on hibernate.org for the tutorial and documentation section to see how to enable it (I don't have my hibernate in action book under my eyes atm). If you don't within the next couple of hour, I'll be able to give you a more concrete sample.

    HTH

    Olivier

    Comment


    • #3
      I'll have a look at the Hibernate docs right now and let you know if I had any succes.

      Comment


      • #4
        I added default-cascade="save-update" to the mapping definition, resulting in:

        <hibernate-mapping default-cascade="save-update" >
        <class name="com.vvdb.bus.metadata.Resource" table="RESOURCE">
        ...
        <many-to-one name="rights" column="rights_uniqueId"/>
        etc.
        </hibernate-mapping>

        The Exception is gone now and all associated classes are stored correctly.

        Thanks Jolly.

        Regards, Thomas

        Comment

        Working...
        X