MappingException:没有JDBC类型的Dialect映射:2002

时间:2014-05-19 15:09:07

标签: java sql hibernate postgresql hql

我尝试通过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,其中保存了全文向量。

1 个答案:

答案 0 :(得分:2)

我用.addEntity(Webpage.class)解决了问题      :

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