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.