Java MappingException:没有JDBC类型的方言映射:2002
我尝试通过Hibernate原生sql接口查询PostgreSQL数据库。但是我得到了Java MappingException:没有JDBC类型的方言映射:2002,java,sql,hibernate,postgresql,hql,Java,Sql,Hibernate,Postgresql,Hql,我尝试通过Hibernate原生sql接口查询PostgreSQL数据库。但是我得到了org.hibernate.MappingException:没有JDBC类型的方言映射:2002 SQL查询相当复杂,但通过(例如)pgAdmin可以很好地工作。有人知道问题出在哪里吗 WebpageDaoImpl.java public PageDto search(final String term, final Long parentNodeId, final String localeCode
org.hibernate.MappingException:没有JDBC类型的方言映射: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();
}
@Embeddable
public class WebpageContent {
private String name;
private String title;
private String description;
private String content;
//...
}
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;
//...
}
注意:表
webpage
还有一个显式创建的列webpage\u tsvector
,其中保存了全文向量 我用.addEntity(Webpage.class)
解决了给定的问题:
hqlQuery = sessionFactory
.getCurrentSession()
.createSQLQuery(buildSearchQuery())
.addEntity(Webpage.class);