• Post Reply Bookmark Topic Watch Topic
  • New Topic

View mapping and query in Hibernate

 
J Chung
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I have a mapping of a view similar to the following:

...
<hibernate-mapping>
<class name="ABCDEF" table="ABCDEF_VW" mutable="false">

<composite-id>
<key-property name="A" column="A" type="String" />
<key-property name="B" column="B" type="String" />
<key-property name="C" column="C" type="String" />
</composite-id>

<property name="D" column="D" type="String" not-null="true" />
<property name="E" column="E" type="String" not-null="true" />
<property name="F" column="F" type="String" not-null="true" />

</class>
</hibernate-mapping>

I'm trying to run the following query:

select distinct B, D from ABCDEF_VW where A = ? order by 2

In my Hibernate DAO class I'm trying to implement the above query with:

List resultList = null;
try {
resultList = session.createCriteria(ABCDEFView.class)
.setProjection(Projections
.distinct(Projections.projectionList().add(
Projections.property("B")).add(
Projections.property("D"))))
.add(Restrictions.eq("A", strA))
.list();
}
catch (HibernateException ex) {
...


The above code always results in the list resultList being empty.

I'd appreciate any insight into what I'm doing wrong and how to code the desired query.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!