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