-->
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: Foreign key as property? (or direct table column access)
PostPosted: Sun Jan 14, 2007 8:16 am 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
I have an object that needs to maintain its relationship to another object as a long/key as opposed to an object. In other words, I need for this one relationship to bypass ORM and use the long value of the foreign key directly.

Normally my relationship is like so

Code:
    <many-to-one name="circuit" class="DBCircuit" column="CircuitID" access="field" lazy="false" not-null="false"/>


But instead of accessing this as the class DBCircuit I want to access the column CircuitID directly. Is this possible?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 2:43 pm 
Beginner
Beginner

Joined: Sat Dec 16, 2006 1:52 pm
Posts: 40
The solution to this is to have one mapping for schema creation that refers to the class that will generate the foreign constraint.
Code:
<many-to-one name="circuit" class="DBCircuit" column="circuitid" access="field" lazy="false" not-null="false"/>


And another mapping for runtime useage that just uses a property. Something like
Code:
<property name="circuit" column="circuitid" access="field" type="long"/>


So far this is working fine. Just as long as the 'type' used for the foreign key is always a long. I don't know how to enforce that in my DDL mapping, but I'm not going to worry about it just yet.


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.