-->
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: Joining tables w/o using a table's primary key
PostPosted: Wed Dec 19, 2007 4:38 pm 
Newbie

Joined: Fri Dec 07, 2007 11:35 am
Posts: 4
How can I use join w/o using the tables primary key when mapping an object?

<join> seems to only allow using the primary key.
<many-to-one> tag seems to require that the property being set is another <class> defined in the xml file

ex:

Java Object:
public class ServiceUser
{
...
private Integer idIndex;
private String loginId;
private String serviceCd;
private String serviceDesc;
...
}

service_user table - table of users and service subscriptions. a login id can subscribe to only one service
id_index INTEGER
c_loginid CHAR(15)
c_servicecd CHAR(3)


service_codes table - master table of available service codes and descriptions (should be read only)
c_servicecd CHAR(3)
c_servicedesc VARCHAR(50)


sample hibernate.cfg.xml
<class name="ServiceUser" table="service_user">
<id name="idIndex" column="id_index" >
<generator class="increment" />
</id>
<property name="loginId" column="c_loginid" />
<property name="serviceCd" column="c_servicecd" />
<join table="service_codes">
<key column="c_servicecd" update="false" />
<property name="serviceDesc" column="c_servicecd" insert="false" update="false"/>
</join>
</class>

when selecting, hibernate tries to join service_user.id_index with service_codes.c_servicecd


replacing the <join> with
<property name="serviceDesc" formula="SELECT sc.c_servicedesc FROM service_codes sc WHERE sc.c_servicecd= serviceCd"/>

doesnt seem to work either, it gives this error: ILLEGAL SYMBOL ".". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: , FROM INTO

Hibernate 3.0
DB2 db


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 4:01 am 
Newbie

Joined: Thu Dec 20, 2007 3:51 am
Posts: 2
it seems that you should put your
Quote:
SELECT sc.c_servicedesc FROM service_codes sc WHERE sc.c_servicecd= serviceCd

into braces and add join inside:
Quote:
<property name="serviceDesc" formula="(SELECT sc.c_servicedesc FROM service_codes sc, service_user su WHERE sc.c_servicecd= su.c_servicecd)"/>


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.