-->
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.  [ 1 post ] 
Author Message
 Post subject: man-to-one mapping - is a real "read-only" possible?
PostPosted: Fri Sep 24, 2010 12:52 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
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>


_________________
Please rate this reply if it helps!!


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

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.