首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在JPA中使用MySQL全文查询而不使用Hibernate-search,Solr和eclipse-link

在JPA中使用MySQL全文查询而不使用Hibernate-search,Solr和eclipse-link
EN

Stack Overflow用户
提问于 2019-05-29 07:11:52
回答 1查看 0关注 0票数 0

目前我正在使用我的maven项目的以下配置。我想在我的代码中使用JPA(JPQL)来使用全文搜索查询。

我尝试了这个建议,但我找不到MySQL5Dialect的maven依赖,它应该与我的下面的配置兼容。

如何使用JPA的MySQL全文搜索

代码语言:javascript
复制
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.4.0.GA</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.1.0.GA</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.3.1.GA</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.4.0.GA</version>
EN

回答 1

Stack Overflow用户

发布于 2019-05-29 17:08:56

我创建了方言自定义类

public class FullTextSearch extends MySQL5InnoDBDialect{

代码语言:txt
复制
public FullTextSearch(){
    super();
    registerFunction("match", new SQLFunctionTemplate(new DoubleType(),"match(?1) against (?2 in boolean mode)"));
}

}

In code I call this method

代码语言:txt
复制
 Query namedQuery = em.createQuery("select user from User user " +
                "where match(user.familyName,LOWER(CONCAT(:searchName,'*'))) > 0 " +
                "order by user.familyName");

I add configuration in persistence.xml

<property name="hibernate.dialect" value="textsearch.FullTextSearch"/>

But I am getting an error

代码语言:txt
复制
WebServiceException: org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException[AbstractEntityManagerImpl.java:614] threw javax.persistence.PersistenceException (org.hibernate.exception.SQLGrammarException: could not execute query)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档