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: Filtering collections
PostPosted: Fri Jun 24, 2011 10:06 am 

Joined: Sat Jun 09, 2007 12:29 pm
Posts: 19
I'm using Spring for my application framework. I've read several posts about an org.hibernate.QueryException: The collection was unreferenced error.

To simplify the calls I created a controller method bellow, which calls Dao layer directly:

@RequestMapping(method=RequestMethod.GET )
   public @ResponseBody Map<String,? extends Object> getAll(
                                    @RequestParam(required=false) String filter,
                                    @RequestParam(required=false) String start,
                                    @RequestParam(required=false) String limit,
                                    @RequestParam(required=false) String sort,
                                    @RequestParam(required=false) String dir
                                    ) {
         Collection<?> results = this.taskDao.getCollection();
         return MessageProcessor.createRecordListMessage(null);
      } catch (Exception e) {
         return MessageProcessor.createError(e.getLocalizedMessage());

Here is my Dao:


package com.objectverse.projects.task.repository;

import java.util.Collection;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.objectverse.projects.task.model.Task;

public class TaskDAO {
   private SessionFactory sessionFactory;
   public TaskDAO() {
   //public <T> Collection<T> getCollection() {
   public Collection<Task> getCollection() {
      Session session = this.sessionFactory.getCurrentSession();
      long size = ((Long)session.createQuery("select count(*) from " + Task.class.getName() + " o ")
      Query query = session.createQuery("select o from " + Task.class.getName() + " o ");
      Collection<Task> records = query.list();
      Collection<Task> filteredCollection = this.filterCollection(records, session);
      return filteredCollection;

   private <T> Collection<T> filterCollection(Collection<T> collection, Session s) {
      Query filterQuery = s.createFilter(collection, "where this.title like 'I%'");
      return filterQuery.list();

The error is raised in the Collection<Task> filteredCollection = this.filterCollection(records, session); line. Why?

Any help appreciated.



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.