Hi all,
I don't know where to search anymore, read the forum messages but thery were not of any help. I have three tables: Order, Orderline and Ticket. An Order object have one or more Orderlines, an orderline have one Ticket and a Ticket may belong to one or more Orderlines.
Order -|-----n-< Orderline > -n------|- Ticket
After construction the persist objects I perform a save(Order), which results in the following exception:
Code:
object references an unsaved transient instance - save the transient instance before flushing: TickTicket
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: TickTicket
at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:610)
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:377)
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 $Proxy0.saveOrder(Unknown Source)
at com.lcmg.ticketing.business.order.impl.OrderServiceImplTest.testGetOrderCreator(OrderServiceImplTest.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Java code (using hibernate 2.1.8):
Code:
TickOrderline tickOrderline = new TickOrderline();
TickOrder tickOrder = new TickOrder();
tickOrder.setTickOrderlines(new HashSet());
tickOrder.getTickOrderlines().add(tickOrderline);
tickOrderline.setTickOrder(tickOrder);
TickTicket tickTicket = new TickTicket();
tickTicket.setTickOrderlines(new HashSet());
tickTicket.getTickOrderlines().add(tickOrderline);
tickOrderline.setTickTicket(tickTicket);
Mapping files:
Code:
---
<class
name="TickOrder"
table="tick_order"
>
<id
name="id"
type="java.lang.String"
column="id"
>
<generator class="uuid.hex" />
</id>
...
<set
name="tickOrderlines"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="tick_order_id" />
</key>
<one-to-many
class="TickOrderline"
/>
</set>
...
</class>
Code:
<class
name="TickOrderline"
table="tick_orderline"
>
<id
name="id"
type="java.lang.String"
column="id"
>
<generator class="uuid.hex" />
</id>
<many-to-one
name="tickOrder"
class="TickOrder"
not-null="true"
>
<column name="tick_order_id" />
</many-to-one>
<many-to-one
name="tickTicket"
class="TickTicket"
not-null="true"
>
<column name="tick_ticket_id" />
</many-to-one>
...
</class>
Code:
<class
name="TickTicket"
table="tick_ticket"
>
<id
name="id"
type="java.lang.String"
column="id"
>
<generator class="uuid.hex" />
</id>
<set
name="tickOrderlines"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="tick_ticket_id" />
</key>
<one-to-many
class="TickOrderline"
/>
</set>
...
</class>
What did I wrong?