Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 是否可以使用hibernate投影按组属性获取(特定列的)列表?_Mysql_Hibernate_Projection_Hibernate Criteria - Fatal编程技术网

Mysql 是否可以使用hibernate投影按组属性获取(特定列的)列表?

Mysql 是否可以使用hibernate投影按组属性获取(特定列的)列表?,mysql,hibernate,projection,hibernate-criteria,Mysql,Hibernate,Projection,Hibernate Criteria,我有一个关键的要求,就是这样 文件表 --------------------------------------------------------------------------------------- id | root_path | folder_name | file_name | user_id -----------------------------------------------------------

我有一个关键的要求,就是这样

文件表

---------------------------------------------------------------------------------------
  id  |      root_path      |     folder_name     |      file_name     |    user_id
---------------------------------------------------------------------------------------
   1  |    common_rootpath  |       folder 1      |       file 1       |        x
   2  |    common_rootpath  |       folder 1      |       file 2       |        x
   3  |    common_rootpath  |       folder 1      |       file 3       |        x
   4  |    common_rootpath  |       folder 1      |       file 4       |        x
   5  |    common_rootpath  |       folder 2      |       file 1       |        x
   6  |    common_rootpath  |       folder 2      |       file 2       |        x
   7  |    common_rootpath  |       folder 2      |       file 3       |        x
   8  |    common_rootpath  |       folder 3      |       file 1       |        x
   9  |    common_rootpath  |       folder 3      |       file 2       |        x
我想得到以下输出

 List ( ( folder_name = folder 1, List( file_name = file1,file2,file3,file4 ) ) ,
        ( folder_name = folder 2, List( file_name = file1,file2,file3 ) ) ,
        ( folder_name = folder 3, List( file_name = file1,file2) ) ,
      )
我知道如果这种关系是一对多的话,这是很容易做到的。但是,如果这些值在同一个表中,有可能吗?我尝试了以下标准,但正如预期的那样,它给我带来了IllegalArgumentException

Criteria cr = getSession().createCriteria(Document.class,"document")
            .createAlias("document.user", "user")
            .setProjection(Projections.projectionList()
                    .add(Projections.property("fileName"),"fileNames")
                    .add(Projections.property("folderName"),"folderName")
                    .add(Projections.groupProperty("folderName")))
                    .add(Restrictions.eq("user.id", id))
                    .setResultTransformer(Transformers.aliasToBean(Document.class));
    return cr.list();
堆栈跟踪:

org.springframework.orm.hibernate4.HibernateSystemException: IllegalArgumentException occurred while calling setter for property [com.site.model.Document.fileNames (expected type = java.util.List)]; target = [com.site.model.Document@59eeb2e4], property value = [myfilename] setter of com.site.model.Document.fileNames; nested exception is IllegalArgumentException occurred while calling setter for property [com.site.model.Document.fileNames (expected type = java.util.List)]; target = [com.site.model.Document@59eeb2e4], property value = [myfilename]
文件名是文档模型类中的列表