mysql 一個錯誤

ldear發表於2017-08-31

@Entity
@Table(name="push")
public class PushEntity  implements Serializable{
    @Id
    @Column(name = "id")
    private String id;
    @Column(name = "title")
    private String title;// 標題 
    @Column(name = "is_send")
    private Integer isSend;// 是否傳送(1,傳送)


@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.



相關文章