• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

Spring with Hibernate Experts please......

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,    

   saveOrUpdate(A)
   saveOrUpdate(B)
   saveOrUpdate(C)

and its giving the following error :

 WARN [http-8080-Processor24] (RequestProcessor.java:509) - Unhandled Exception thrown: class org.springframework.dao.InvalidDataAccessApiUsageException
ERROR [http-8080-Processor24] (StandardWrapperValve.java:269) - 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(SessionFactoryUtils.java:621)
      at org.springframework.orm.hibernate.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:572)
      at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:484)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:397)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:243)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:66)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
      at $Proxy14.saveIssue(Unknown Source)
      at com.mmi.intouch.web.action.IssueDetailAction.execute(IssueDetailAction.java:232)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Unknown Source)


Help please.....
0
letsbedecent
Asked:
letsbedecent
  • 3
1 Solution
 
letsbedecentAuthor Commented:
Hello,

 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 !!

thanks.
0
 
aozarovCommented:
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?
0
 
letsbedecentAuthor Commented:
I used Hibernate component and included everything in one object.
0
 
letsbedecentAuthor Commented:
well, not everything, but say., moved B to C then used another page to edit A.... totally seperated everything, instead of tying them together.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now