String sql = "SELECT COUNT(*) as count, Date(created) as date FROM redeem_code_history WHERE merchant_user_id = :merchantUserId GROUP BY Date(created) ORDER BY created DESC";
Query query = getEM(true).createNativeQuery(sql);
query.setParameter("merchantUserId", merchantUserId);
query.setFirstResult(offset).setMaxResults(limit);
query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List<Map<String, Object>> resultList = query.getResultList();
return resultList;
@NamedQuery(name = "OfferCoupon.getByHistoryId", query = "FROM OfferCoupon oc WHERE oc.couponHistoryId = :couponHistoryId")
List rows = this.getEM(true).createNamedQuery("OfferCoupon.getByHistoryId", OfferCoupon.class)
.setParameter("couponHistoryId", couponHistoryId).getResultList();
public void save(LogAPI logAPI, String tableSuffix) {
StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO ");
sql.append("log_api_").append(tableSuffix);
sql.append(" SET user_id = :userId, uri = :uri, app_id = :appId, user_agent = :userAgent").append(
", method = :method, params = :params, created = :created");
Query query = entityManager.createNativeQuery(sql.toString());
query.setParameter("userId", logAPI.getUserId());
query.setParameter("uri", logAPI.getUri());
query.setParameter("appId", logAPI.getAppId());
query.setParameter("userAgent", logAPI.getUserAgent());
query.setParameter("method", logAPI.getMethod());
query.setParameter("params", logAPI.getParams());
query.setParameter("created", logAPI.getCreated());
query.executeUpdate();
}