-->
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: subselect mapping
PostPosted: Thu Feb 23, 2006 6:49 pm 
Newbie

Joined: Thu Feb 23, 2006 5:52 pm
Posts: 1
First of all, I'm very new to Hibernate and I have been looking thru the various docs and examples to get a simple question answered without success.

I have a very simple requirement. I want to be able to create a SQL query using the <subselect> element (or its equalent atttibute) to map to a single POJO type (immutable and read-only). Simple, isn't it?

This query can be a bit complex in that it can involve table joins, wrapping functions around the selected columns, etc.

<hibernate-mapping package="eg">
<class name="Summary">
<subselect>
select item.name, max(bid.amount), count(*)
from item
join bid on bid.item_id = item.id
group by item.name
</subselect>
<synchronize table="item"/>
<synchronize table="bid"/>
<id name="name"/>

<property name="name" column="name"/>
<property name="amount" column="??????"/>
<property name="count" column="??????"/>
...
</class>


For the property mapping, what is the corresponding column name?


Top
 Profile  
 
 Post subject: Re: subselect mapping
PostPosted: Fri Mar 02, 2007 12:53 pm 
Newbie

Joined: Wed Sep 27, 2006 4:07 pm
Posts: 9
I am a Hibernate newbie myself. But if I understand your scenario, I believe all you need are aliases for your computed columns, like this:

Code:
<hibernate-mapping package="eg">
<class name="Summary">
    <subselect>
        select item.name, max(bid.amount) as maxamt, count(*) as cnt
        from item
        join bid on bid.item_id = item.id
        group by item.name
    </subselect>
    <synchronize table="item"/>
    <synchronize table="bid"/>
    <id name="name"/>
       
    <property name="name" column="name"/>
    <property name="amount" column="maxamt"/>
    <property name="count" column="cnt"/>
...
</class>

_________________
Stephen Schaub


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.