-->
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: Composite-Id, Aggregate function Query
PostPosted: Thu Apr 15, 2004 12:13 am 
Newbie

Joined: Thu Apr 15, 2004 12:08 am
Posts: 1
I have a simple scenario : My table config looks like this:

Code:
<class name="org.jvending.datastructure.CatalogProperty" table="catalog_property">
      <composite-id name="pkey" class="org.jvending.datastructure.ParClientIdPk" >
         <key-property name="parid" column="parid" />
         <key-property name="clientbundleid" column="clientbundleid" />   
         <key-property name="id" column="id" />
      </composite-id>
      <property name="name" column="catalog_property_name" />
      <property name="value" column="catalog_property_value" />       
</class>


One Table CatalogProperty - 5 Columns, 3 form composite Key.

The following code works very fine, but I do not understand what is at List.get(0) ? Why 2 elements in the list I'll get one max(id) ?? (This is not the case for non aggregate functions - ref manual - chapter 11 getBlogAndAllItems method)


Code:
Query q = session.createQuery(
            "select max(cp.pkey.id) " +
            "from org.jvending.datastructure.CatalogProperty as cp  " +
            "where cp.pkey.parid = :name1 and  cp.pkey.clientbundleid = :name2"
            );
                  
         q.setString("name1", parid );
         q.setString("name2", clientbundleid ) ;         
         List l = new ArrayList();         
         l = q.list() ;          
         if (l.size()==2)      
            in = (Integer) l.get(1);



I am using hibernate-2.1.2, mySql 4.0.17 -nt Database.

Thanks a lot for the response and your time.
Regards,
Rashmi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 3:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Look at the SQL query generated and at the results.


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.