I'm sure I shouldn't be trying to do this late at night, and should wait for the clarity of daylight, but anyway...
I'm using Hibernate with Struts in a web application. I have an Order class which contains a Customer object as a property. In my app, I gather the details of the Order on an HTML form, which is then used to populate a form bean. This form bean is then used to construct the Order object which is stored in the database. Now, unless I construct a Customer object and assign it to the Order as part of this process, my order ends up without a customer. But if I do so, I get an error:
org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: testing.om.Customer
But I don't want to save the customer - no changes could have taken place with it, and all I really need is its ID property which Hibernate uses. I don't have or require any cascading between order and customer. This is from the Order mapping:
<many-to-one
name="customer"
class="testing.om.Customer"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="customer_id"
/>
Is there some way I can just use the ID and be done with it? Or do I need to load the existing Customer from the database and use that?
|