-->
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.  [ 4 posts ] 
Author Message
 Post subject: Criteria Projection and Many-to-Many field
PostPosted: Sat Jul 26, 2008 10:06 am 
Newbie

Joined: Sat Jul 26, 2008 9:46 am
Posts: 2
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 5:09 am 
Newbie

Joined: Fri Aug 22, 2008 6:12 am
Posts: 13
Hello Mark,

I'm actually faceing the same problem. Did you found a solution?

Greets
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 2:26 pm 
Newbie

Joined: Sat Jul 26, 2008 9:46 am
Posts: 2
Hi Chris, I would love to tell you that I found a solution, but as yet this is the issue at the bottom of my pile - entitle - I have no idea what to do about this. I can understand the problem from an SQL POV in that there is no join which would be able to populate the Collection, however I thought Hibernate would have a way around it using multiple fetches...

Sorry, probably not what you were after, still with the thread jumping back to the top of the list, maybe someone will see it and give us that snippet of information which eventually unravels into a useful result!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 3:43 am 
Newbie

Joined: Fri Aug 22, 2008 6:12 am
Posts: 13
Anyway, thanks for the quick response. If I find something out I'll let you know. Until then I'll try to build a workaround, or somethink like that ... :/

_________________
believing in the impossible makes it possible


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

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.