Hi,
I am relatively new to Hibernate, so this could be a really daft question showing fundamental ignorance! I have read through the documentation and the posts here, and can not see a problem with what I am doing - clearly there is though!
I am using the Criteria API to fetch some records from my database, Projections to restrict which fields are returned. I am using a result transformer and aliases to get my resultSet as a Map. This is working perfectly, except for in the case of two fields, which I was hoping would return a List<Object> as they are many-to-many fields... They are in fact both coming back null - no exceptions thrown.
Here I think are the pertinent bits of information:
For the search:
Code:
...
Criteria topCriteria = session.createCriteria(Contact.class);
topCriteria.setFetchMode("client", FetchMode.JOIN);
topCriteria.setFetchMode("nowActions", FetchMode.JOIN);
Projection topProjection = Projections.projectionList()
.add(Projections.alias(Projections.property("nowActions"), "nowActions")
.add(Projections.alias(Projections.property("date"), "date")
topCriteria.setProjection(topProjection);
topCriteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
List<Map<String, Object>> results = (List<Map<String, Object>>) topCriteria.list();
...
From contact.hbm.xml
Code:
<set name="nowActions" table="contacttonowaction">
<key>
<column name="contactId" not-null="true" />
</key>
<many-to-many class="uk.co.now.data.hbn.Nowaction" >
<column name="actionId"/>
</many-to-many>
</set>
Maybe that is all that is needed. Needless to say there is data in the database, and the attribute "date" above gets populated just fine. It is also true to say that a fetch without the Projections returns everything just fine, unfortunately, right now, I don't want everything.
Anything glaringly obvious that I am doing wrong? Any suggestions appreciated,
Thanks, Mark.