I've searched for answers and have tried a few things, and now i am wondering if what i would like to do is even possible.
Mapping Class A which contains a reference to Class B. Straight Forward.
Scenario, i have Transaction, which references Customer. Customer is maintained independently, generally outside the context of the Transaction. While a Customer can be attached to a transaction, it will always be an existing one. In fact, i have no issue with Transient Object exceptions here.
However, i do not want changes to Customer to happen in the context of Transaction. So, if changes are made to Customer after loading Transaction, i wish them to be ignored.
Okay, so i've tried the following, see a fuller mapping below.
Code:
<many-to-one name="customer" insert="false" update="false" class="Customer" column="Customer_ID" />
<many-to-one name="customer" cascade = "none" class="Customer" column="Customer_ID" />
<many-to-one name="customer" insert="false" update="false" cascade="none" class="Customer" column="Customer_ID" />
When running test code that simply loads the transaction and sets a new customer name, the name is always persisted.
I'm guessing i am not understanding the real meaning of cascade = 'none', and insert/update = 'false'
Is there any way of doing this. I would like this to be implicit. I can't afford to find all the places developers might load Transaction and evict Customer.
Code:
MAPPINGS
<class name="Transaction" table="Transaction">
<id name="id" column="ID" type="long">
<generator class="native" />
</id>
<property .../>
<property .../>
<many-to-one name="customer" class="Customer" column="Customer_ID" />
</class>
<class name="Customer" table="Customer">
<id name="id" column="ID" type="long">
<generator class="native" />
</id>
<property .../>
<property .../>
</class>