Example usage for org.hibernate SharedSessionContract createNativeQuery

List of usage examples for org.hibernate SharedSessionContract createNativeQuery

Introduction

In this page you can find the example usage for org.hibernate SharedSessionContract createNativeQuery.

Prototype

NativeQuery createNativeQuery(String sqlString);

Source Link

Document

Create a NativeQuery instance for the given native (SQL) query

Usage

From source file:com.romeikat.datamessie.core.base.dao.impl.DocumentDao.java

License:Open Source License

public List<LocalDate> getPublishedDates(final SharedSessionContract ssc) {
    // Query/*from   w  w w  .  ja  v a 2 s .  com*/
    final StringBuilder hql = new StringBuilder();
    hql.append("SELECT DISTINCT DATE(d.published) ");
    hql.append("FROM document d ");
    hql.append("WHERE d.published IS NOT NULL ");
    @SuppressWarnings("unchecked")
    final Query<Date> query = ssc.createNativeQuery(hql.toString());

    // Execute
    final List<Date> publishedDates = query.list();
    return Lists.transform(publishedDates, d -> DateUtil.toLocalDate(d));
}