I have this piece of code:
public String getEventsForCalendar(@RequestParam("userId") Long userId){
Session session = NewHibernateUtil.getSessionFactory().getCurrentSession();
try{
session.beginTransaction();
JSONArray eventsArray = new JSONArray((List<Event>)(session.createCriteria(Event.class)
.add(Restrictions.eq("ownerid", userId))
.list()));
User user = (User)session.createCriteria(User.class)
.add(Restrictions.eq("id", userId)).uniqueResult();
for (Event event: (List<Event>) session.createCriteria(Event.class)
.add(Restrictions.ne("ownerid", userId))
.list()){
if (event.getInvited().contains(user)){
eventsArray.put(new JSONObject(event));
}
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
return null;
}
It, at first, should find Events created by User. Next, in loop it should get Events which User is invited. Each Events has List called invited and I think I have to iterate over all list and check if User is in invited list, but can I do something like?
List<Event> list = session(...)
.add(Restrictions.eq("invited", user);
In the other words, can I get from database Object which in list contains object? I will be very happy if anybody answers my question - thank you in advance.