-->
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.  [ 1 post ] 
Author Message
 Post subject: Three Tables and Restrictions
PostPosted: Mon Feb 21, 2011 11:30 am 
Newbie

Joined: Mon Feb 21, 2011 10:41 am
Posts: 1
Hello guys,

I am trying to create a simple request over three tables, using criteria an restrictions.
Or, otherwise, accessing an object which is in a list of objects which is part of an object :)

Description:

There is an object "Message" containing a list of "Recipients".
Now I want to check if a certain message, belonging to a single recipient which is/ or is not, part of that list of recipients.

Code:
       if (messageCriteria.getRecipientId() != null) {
            criteria.createAlias("recipients", "recipients").add(
                    Restrictions.eq("message.recipients.recipient", messageCriteria.getRecipientId()));
        }


obvious error in the propertymodel would be that "recipients.recipient" does not work, while recipients being a list and recipient an object, as part of that list.

In SQL my statement would look like this:
Code:
SELECT message.id FROM message, message_messagerecipient, messagerecipient WHERE message_messagerecipient.recipients_id = messagerecipient.id AND message.id = message_messagerecipient.message_id AND messagerecipient.recipient_id = 1;


Where "1" is represented by messageCriteria.getRecipientId();

Tables are:

MESSAGE:
ID

MESSAGE_MESSAGERECIPIENT:
MESSAGE_ID => ID of message from table Message
RECIPIENTS_ID => ID of recipient in table Messagerecipient

MESSAGERECIPIENT:
ID
RECIPIENT_ID => ID of actual recipient which is searched by

At the end I want to return all messages.
Any hints how to solve this using either restrictions or any other solution but typing an SQL statement?

Cheers,
Chris


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

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.