-->
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: Fetch only one column using hibernate 3.0
PostPosted: Sun Jan 18, 2009 9:36 am 
Newbie

Joined: Wed Oct 15, 2008 12:43 pm
Posts: 4
I have a table(USER) and view(PERSON). These two are related in one-to-one way with PERSON_ID in
both the tables. But User table primary key is USER_ID and not PERSON-ID.
I want to fetch only one column PERSON.CITY and this should be readonly fetch. Anyway person is view.

So if I put one-to-one, then whole object(with 50 col) is fetched which is a overkill. Based on common key,
I only want to fetch one column from PERSON and put that as property of User.
I have this as a formula, but my colleague is opposing this idea since it becomes a sub-query.
So what are the other ways of achiving this?

<hibernate-mapping>
<class name="User" lazy="false" table="User">
<id
name="userid"
type="long"
column="USER_ID"
length="10"
>
<generator class="sequence">
<param name="sequence">sq_soceval</param>
</generator>
</id>
<property
name="name"
type="string"
column="name"
length="100"
/>
<property
name="person-id"
type="string"
column="person-id"
length="30"
/>


...

<many-to-one name="person" class="Person" column="PERSON_ID" unique="true"/> --> fetches whole obj?

<property
name="city"
type="string"
column="Person.City" ====> I want something like this. Should come from Person.
length="100"
/>

..
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="Person" lazy="false" table="Person" mutable="false">

<id
name="PERSON_ID"
type="string"
column="PERSON_ID"
length="30"/>
<property
name="city"
type="string"
column="city"
length="300"
/>
....
</class>
</hibernate-mapping>

I have it implemented as:
<property
name="city"
type="string"
formula="( select p.city from person p where p.person-id = person-id )"
insert="false"
update="false"
lazy="false"
/>

I want to get ideas for better ways of implementing this. Thank you for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 1:11 am 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
did u tried the component thing ?


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.