• Post Reply Bookmark Topic Watch Topic
  • New Topic

View mapping and query in Hibernate  RSS feed

 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!