---
# System prepended metadata

title: JPQL
tags: [Java, JPA, Spring]

---

# JPQL
###### tags: `JPA` `Spring` `Java` 
**EntityManager#createQuery(String qlStr)** 
透過此方法獲得Query Object
String sql = " FROM XXX C WHERE C.XXX = ? ";//回傳XXX物件
String sql = " SELECT C.A , C.B FROM XXX C WHERE C.XXX = ? ";//回傳List<Object[]>
String sql = " SELECT new XXX(C.A , C.B) FROM XXX C WHERE C.XXX = ? ";//回傳List<XXX>但須建立特定建構子


**EntityManager#createNamedQuery(String name)**
**EntityManager#createNativeQuery(String sqlStr)** 原生SQL
**EntityManager#createNativeQuery(String sqlStr,resultSetMapping)**原生SQL