@PersistenceContext private EntityManager em;
String appSql = "SELECT\n" + "\tid,\n" + "\ttitle,\n" + "\tdigest,\n" + "\tditch,\n" + "\tcontent,\n" + "\tscope,\n" + "\tis_send,\n" + "\tsend_status,\n" + "\topen_num \n" + "FROM push \n" + String formatAppSql = String.format(appSql,PushConstant.SendStatus.NO_SEND,PushConstant.ditch.APP ,currentDate); Query appQuery = em.createNativeQuery(formatAppSql, PushEntity.class); List listObj = appQuery.getResultList();
例如
SELECT id AS id,is_send AS isSend FROM push
sql 这样写会报错,去掉as 别名,就能执行ok.