-->
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: Just want a column of a child table included in a class.
PostPosted: Tue Sep 14, 2004 6:45 pm 
Newbie

Joined: Tue Sep 14, 2004 6:24 pm
Posts: 1
Given a Device, I want to include the device_type_name property (from a foreign table) in the Device object: I do NOT want a reference to the entire DEVICE_TYPE row or an entire Device_type object (composition).

The relational DB tables are (pseudo code to keep it short)

Code:
DEVICE
    device_id     bigint
    device_name varchar
    device_type_fk bigint   references DEVICE_TYPE
    ...

and

DEVICE_TYPE
    device_type_id  bigint
    device_type_name varchar
    ...

For context, lets asssume that a device_type object is a hugely unwieldy thing that I'd rather not have in this particular application.

The Java Object I do want looks like:

Code:
class Device
    long device_id
    String deviceName
    String deviceTypeName

Note that this class has a device_type_name, NOT a device_type_fk or device_type object.

A typical SQL select to achive what I want would be:

Code:
select device_id, device_name, device_type_name from DEVICE d, DEVICE_TYPE dt
where d.device_type_fk = dt.device_type_id


HOW DO I CREATE A MAPPING TO EXPRESS THE Device CLASS, GIVEN THE DEVICE AND DEVICE_TYPE TABLES?

Code:
<hibernate-mapping>
  <class name="Device" table="DEVICE">
     <id name="deviceID" column="device_id" type="long" />
        <property name="deviceName" column="device_name" type="string"/>
        <!-- THIS IS CERTAINLY WRONG: -->
        <property name="deviceTypeName" column="?????device_type.device_type_name" type="string"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 1:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you can use a formula, but you can't update this property then...

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.