-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Annotating object relationships
PostPosted: Wed Jul 30, 2008 10:54 pm 
Newbie

Joined: Sun Jul 27, 2008 4:23 am
Posts: 10
OK, I have the following objects

InsuranceSearchData
Driver
Vehicle
Incident

InsuranceSearchData can have zero or more Drivers (List<Driver>), and zero or more Vehicles (List<Vehicle>).

A Vehicle has a primary driver and a list of zero or more secondary drivers (List<Driver>), but should be able to be saved before the primary driver is set.

A Driver as zero or more incidents (List<Incident>)

For business reasons, the data should be able to be saved to the database as information is entered, which means that a Vehicle will be saved before its drivers are set, a Driver will be saved before its incidents are set, etc.

The schema is auto-generated using hibernatetool

I'd annotated them as follows (leaving out much of the other detail):

Code:
InsuranceSearchData:

@CollectionOfElements
private List<Driver>               driverList;
@CollectionOfElements
private List<Vehicle>             vehicleList;

Driver:

@OneToMany
private List<Incident>              incidentList;

Vehicle:
@ManyToOne
private Driver primaryDriver;
@ManyToMany
private List<Driver> secondaryDriver;


I'm assuming I need some additional annotations to make everything work. Any ideas here?


Top
 Profile  
 
 Post subject: Here's the traceback that occurs when I try to save
PostPosted: Wed Jul 30, 2008 11:30 pm 
Newbie

Joined: Sun Jul 27, 2008 4:23 am
Posts: 10
when Vehicle has been set but no drivers (yet).
Code:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: net.oversee.oms.insurance.model.Vehicle; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: net.oversee.oms.insurance.model.Vehicle
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)
   org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: net.oversee.oms.insurance.model.Vehicle; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: net.oversee.oms.insurance.model.Vehicle
   org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:636)
   org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:738)
   org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:614)
   org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
   org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
   org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
   org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   $Proxy20.saveInsuranceSearch(Unknown Source)
   net.oversee.oms.insurance.model.InsuranceSearch.saveInsuranceSearchData(InsuranceSearch.java:41)
   net.oversee.oms.insurance.webapp.AutoInsWizardController.postProcessPage(AutoInsWizardController.java:350)
   org.springframework.web.servlet.mvc.AbstractWizardFormController.processFormSubmission(AbstractWizardFormController.java:505)
   org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
   org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
   org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
   org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.