简体   繁体   English

JPQL Like语句未返回结果

[英]JPQL Like statement not returning results

I have a FILE table within my application (using postgreSQL) which stores off the full path of a file I have on my OS. 我的应用程序中有一个FILE表(使用postgreSQL),该表存储了我操作系统上文件的完整路径。

When I try and do a 'like' query, I keep getting zero results when I know there is data saved. 当我尝试执行“喜欢”查询时,当我知道有保存的数据时,结果一直为零。

Here's the query in question: 这是有问题的查询:

public List<MyFile> getDirectoryFiles(Path path) {
        Query query = em.createQuery("from MyFile f WHERE f.path LIKE :path");
        query.setParameter("path", "////data////myData////.settings% ESCAPE '//'");  // hard coded the path for testing
        return query.getResultList();
}


@Override
public void deleteDirectoryFiles(Path path) {
    for(MyFile file : this.getDirectoryFiles(path)){
        this.delete(file);
    }
}


// in some other method I am deleting the files from a directory
Foo.deleteDirectoryFiles(this);  // points to '/data/myData/.settings'

Not sure why this is happening. 不知道为什么会这样。 When I take what hibernate is producing and plugin the absolute path, I do see the returned tuples within my database. 当我选择休眠产生的东西并插入绝对路径时,我确实在数据库中看到了返回的元组。

Has anyone ever dealt with this issue? 有没有人处理过这个问题? If so, how did you solve the problem? 如果是这样,您如何解决问题? I've tried hardcoding my ':path' variable to be "'/data/myData/.settings%'", "%/data/myData/.settings%", "//data//myData//.settings%" and still nothing is being returned. 我尝试将':path'变量硬编码为“'/data/myData/.settings%'"、"%/data/myData/.settings%"、"//data//myData//.settings% ”,但仍未返回任何内容。 There are no errors, but I cannot figure out why there are no results. 没有错误,但是我无法弄清楚为什么没有结果。

You have wrong syntax in you query, it looks more like HQL query than JPQL. 您的查询语法有误,它看起来更像是HQL查询而不是JPQL。 The correct query should be like this: 正确的查询应如下所示:

em.createQuery("SELECT f FROM MyFile f WHERE f.path LIKE :path");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM