Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MappingException: No Dialect mapping for JDBC type: 2002

I try to query PostgreSQL database via Hibernate native sql interface. But I'm getting org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002

SQL query is quite complex, but via (e.g.) pgAdmin works fine. Does anyone have any idea where the problem should be?

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();
}

Webpage.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;
    //...
}

Note: Table webpage has one more explicit created column webpage_tsvector, wherein is saved fulltext vector.

like image 613
Peter Jurkovic Avatar asked Mar 08 '26 21:03

Peter Jurkovic


1 Answers

I solved given problem with .addEntity(Webpage.class)
:

hqlQuery =  sessionFactory
            .getCurrentSession()
            .createSQLQuery(buildSearchQuery())
            .addEntity(Webpage.class);
like image 160
Peter Jurkovic Avatar answered Mar 10 '26 12:03

Peter Jurkovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!