-->
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.  [ 1 post ] 
Author Message
 Post subject: NEWBIE trasform Projection returnResult from scalar2entity
PostPosted: Thu Feb 15, 2007 12:24 pm 
Newbie

Joined: Thu Feb 15, 2007 10:31 am
Posts: 1
Hi *,
I need a way to obtain a valid entity from a criteria with projection.
Hi had sucess with a SQLQuery:
Code:
SQLQuery tds = _hsession
        .createSQLQuery(
                "select ADDRESS_PROVINCE_NATION_CODE NATION_CODE, ADDRESS_PROVINCE_CODE CODE, COUNT(*) NUM_DRIVERS"
                + " from WMS_DRIVER"
                + " group by ADDRESS_PROVINCE_NATION_CODE, ADDRESS_PROVINCE_CODE")
                ;
       
       tds.addEntity("this", DriverByProvince.class);
        List l = tds.list();


in this way I had a list of
Quote:
DriverByProvince.class
.
The hbm fore
Quote:
DriverByProvince.class
is
Code:
<hibernate-mapping>
   <class name="com.logit.hibernate.DriverByProvince">
      <composite-id name="comp_id"
         class="com.logit.hibernate.DriverByProvincePK">
         <key-property name="nationCode" column="NATION_CODE"
            type="java.lang.String" length="10">
         </key-property>
         <key-property name="code" column="CODE"
            type="java.lang.String" length="10">
         </key-property>
      </composite-id>
      <property name="numDrivers" type="java.lang.Integer"
         column="NUM_DRIVERS" />
      <!-- Associations -->



      <many-to-one name="province"
         class="com.logit.hibernate.Province" update="false" insert="false">
         <column name="NATION_CODE" />
         <column name="CODE" />
      </many-to-one>

   </class>
</hibernate-mapping>


I guess that I can do the same with criteria but till now I've not success.
My idea was to have somsthing similar to
Code:
Criteria crit = session.createCriteria(Driver.class)
        .createAlias("addressProvince", "p")
        .setProjection( Projections.projectionList()
                .add(Projections.groupProperty("p.nation.code"))
                .add(Projections.count("p.nation.code"))
                )
        .setResultTransformer(Transformers.toEntity("this", DriverByProvince.class));


Unfortunatly i event found the equivalent for Transformers.toEntity(...). I've worked a little with ResultTrasformer but with out result because I havent foud a way to traslate scalar result to entity.

Some body knows the right way to do it?
thanks
d.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.