【问题标题】:MappingException: No Dialect mapping for JDBC type: 2002MappingException:没有 JDBC 类型的方言映射:2002
【发布时间】:2014-07-07 14:52:48
【问题描述】:

我尝试通过 Hibernate 本机 sql 接口查询 PostgreSQL 数据库。但我收到org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002

SQL 查询相当复杂,但通过(例如)pgAdmin 可以正常工作。有谁知道问题出在哪里?

WebpageDaoImpl.java

    public PageDto search(final String term, final Long parentNodeId, final String localeCode){
        hqlQuery =  sessionFactory.getCurrentSession().createSQLQuery(buildSearchQuery(false));                 
        hqlQuery.setCacheable(false);
        hqlQuery.setString("locale", localeCode);
        hqlQuery.setString("query", term);
        hqlQuery.setString("fullTextQuery", term.replace(" ", "&"));
        hqlQuery.setLong("nodeId", parentNodeId);
        items.setItems(hqlQuery.list());
    }

  private String buildSearchQuery(){
    StringBuilder sql = new StringBuilder();
    sql.append("with recursive tmp_webpage(id, parent) as ( ")
   .append("    values(cast(-1 as bigint), cast(:nodeId as bigint)) ")
   .append(" union all ")
   .append("    select w.id, w.parent_id ")
   .append("    from tmp_webpage as tw, webpage as w ")
   .append("    where w.id = parent ")
   .append(" ) ")
   .append("SELECT w FROM webpage w ")
   .append("    inner join webpage_content wc ON w.id=wc.webpage_id ")
   .append("WHERE wc.localized_key= :locale AND w.enabled=true (")
   .append("    unaccent(lower(wc.title)) like CONCAT('%', unaccent(lower(:query)) , '%') OR ")
   .append("    wc.webpage_tsvector @@ to_tsquery( cast( wc.localized_key as regconfig), :fullTextQuery) ) ");
   .append("GROUP BY w.id, wc.webpage_tsvector, wc.localized_key ")
   .append("ORDER BY ts_rank(wc.webpage_tsvector, to_tsquery(cast( wc.localized_key as regconfig), :fullTextQuery )) DESC");
   return sql.toString();
}

网页.java

public class Webpage{

    private Long id;
    private Webpage parent;
    private Set<Webpage> childrens;
    // ...

    @ElementCollection
    @CollectionTable(name = "webpage_content")
    @MapKeyJoinColumn(name = "locale")
    private Map<String, WebpageContent> localized;

    //...
}

WebpageContent.java

@Embeddable
public class WebpageContent {

    private String name;
    private String title;
    private String description;
    private String content;
    //...
}

注意:表webpage 有一个更显式创建的列webpage_tsvector,其中保存了全文向量。

【问题讨论】:

    标签: java sql hibernate postgresql hql


    【解决方案1】:

    我用.addEntity(Webpage.class)解决了给定的问题

    hqlQuery =  sessionFactory
                .getCurrentSession()
                .createSQLQuery(buildSearchQuery())
                .addEntity(Webpage.class);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-08
      • 2015-03-27
      • 2014-03-05
      • 2023-03-17
      • 2012-06-18
      相关资源
      最近更新 更多