Good Morning, Comrades,
I have got a criteria that fetches a unique result (StaffShortInbox) inside which there is a set of posts (Post). I am trying to order the set inside the unique result by one of the properties (order by Post.posted). Consider the following classes:
StaffShortInbox Fields: Long staffId; String firstName; String surname; Set posts = new HashSet(0); //contains a set of Posts VISIBLE by a staff member
Post Fields: Long postId; StaffShort staff; //contains the OWNER of the post String post; Date posted; //the field the elements within the set to be ordered by
If I use the following fetching code, the "could not resolve property: posts.posted of: snowhouse.StaffShortInbox" error occurs. This is probably caused by the posts.posted hierarchy relation in ".addOrder(Order.desc("posts.posted"))" line.
StaffShortInbox inbox = (StaffShortInbox) connection.createCriteria(StaffShortInbox.class) .add(Expression.eq("staffId", staffId)) .setFetchMode("posts", FetchMode.JOIN) .setFetchMode("posts.staff", FetchMode.JOIN) .addOrder(Order.desc("posts.posted")) .uniqueResult();
If I use the following code, the JOIN fetching fails causing the "failed to lazily initialize a collection of role: snowhouse.StaffShortInbox.posts" error as I HAVE TO close the session before the unique result is returned.
StaffShortInbox inbox = (StaffShortInbox) connection.createCriteria(StaffShortInbox.class) .add(Expression.eq("staffId", staffId)) .setFetchMode("posts", FetchMode.JOIN) .setFetchMode("posts.staff", FetchMode.JOIN) .createCriteria("posts") .addOrder(Order.desc("posted")) .uniqueResult();
What are my options in this situation?
M.
Last edited by MountainBeast on Tue May 18, 2010 8:48 am, edited 1 time in total.
|