Spring with Hibernate Experts please......

Posted on 2005-04-29
Last Modified: 2013-11-24
Hi all,

  The situation,

  I have three objects A,B,C     relations are (A->C  one to many)   and (B->C one to many)

  Situation, i have only one form to insert all the three..... A,B, and C.

  I am first inserting A and B (without any problem),   but to insert C as you might have guessed i need the A and B objects ( because relations are maintained by hibernate and if we set an object it will insert its corresponding id's  in its many-to-one column)  

What i am doing is,    


and its giving the following error :

 WARN [http-8080-Processor24] ( - Unhandled Exception thrown: class org.springframework.dao.InvalidDataAccessApiUsageException
ERROR [http-8080-Processor24] ( - Servlet.service() for servlet action threw exception
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: com.mmi.intouch.model.PhysicalLocation
      at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(
      at org.springframework.orm.hibernate.HibernateTransactionManager.convertHibernateAccessException(
      at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(
      at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(
      at $Proxy14.saveIssue(Unknown Source)
      at com.mmi.intouch.web.action.IssueDetailAction.execute(
      at org.apache.struts.action.RequestProcessor.processActionPerform(
      at org.apache.struts.action.RequestProcessor.process(
      at org.apache.struts.action.ActionServlet.process(
      at org.apache.struts.action.ActionServlet.doPost(
      at javax.servlet.http.HttpServlet.service(
      at javax.servlet.http.HttpServlet.service(
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(
      at org.displaytag.filter.ResponseOverrideFilter.doFilter(
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(
      at org.apache.catalina.core.StandardWrapperValve.invoke(
      at org.apache.catalina.core.StandardContextValve.invoke(
      at org.apache.catalina.core.StandardHostValve.invoke(
      at org.apache.catalina.valves.ErrorReportValve.invoke(
      at org.apache.catalina.core.StandardEngineValve.invoke(
      at org.apache.catalina.connector.CoyoteAdapter.service(
      at org.apache.coyote.http11.Http11Processor.process(
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(
      at org.apache.tomcat.util.threads.ThreadPool$
      at Source)

Help please.....
Question by:letsbedecent

    Author Comment


     I am actually doing a saveOrUpdate(C) and the above error is caused.
     I did not save the A and B Objects

     When i am saving A and B and then saving C , its saying hibernate session not synchronized with database !!

    LVL 15

    Accepted Solution

    I assume before you saveOrUpdate(C) you associate A and B to C.
    e.g. c.setA(...) and c.setB(...)
    How do you get A and B in order to do that? Do you load them in a different session?

    Author Comment

    I used Hibernate component and included everything in one object.

    Author Comment

    well, not everything, but say., moved B to C then used another page to edit A.... totally seperated everything, instead of tying them together.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Unable to open debugger port in Intellij idea 6 39
    pairstar challenge 2 26
    parentbit challenge 3 37
    Starting to learn JAVA, 7 35
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now