JPA 連表查詢
A表和B表
@Entity
@Table(name = "A", schema = "kps", catalog = "kps")
@DynamicUpdate
public class A implements java.io.Serializable {
private String aUUID;
//關聯B
private B b;
@OneToOne(fetch = FetchType.EAGER, optional = true)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "aUUID", referencedColumnName = "aUUID", insertable = false, updatable = false)
public B getB() {
return b;
}
public void setB(B b) {
this.b= b;
}
}
@Entity
@Table(name = "B", schema = "kps", catalog = "kps")
@DynamicUpdate
public class B implements java.io.Serializable {
private String bUUID;
private Integer age;
}
JPA查詢時
@Override
public PageResult<A> pagedListForVaild(A entity, Integer currentPage, Integer pageSize,
Order... orders) throws Exception {
// 構建查詢條件
Specification<A> sf = new Specification<A>() {
@Override
public Predicate toPredicate(Root<A> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> list = new ArrayList<Predicate>();
Join<A, B> join = root.join("b", JoinType.INNER);
list.add(cb.equal(join.<String>get("age"), Age));
return cb.and(list.toArray(p));
}
};
return super.gerPageResult(currentPage, pageSize, sf, orders);
}
PS:Dao使用@Query註解,也會查詢到關聯物件。
相關文章
- Spring JPA 聯表查詢Spring
- Spring Data JPA 實現聯表查詢Spring
- spring data jpa 多對一聯表查詢Spring
- spring data jpa查詢Spring
- SpringBoot + JPA的自學之路(三)多表連線查詢Spring Boot
- sql 連線查詢例項(left join)三表連線查詢SQL
- MySQL join連表查詢示例MySql
- 1112跨表連線查詢
- JPA多表關聯查詢
- jpa一對多查詢
- JPA時間段查詢
- jpa動態查詢與多表聯合查詢
- SpringBoot Jpa多條件查詢Spring Boot
- JPA的多表複雜查詢
- Spring JPA 定義查詢方法Spring
- JPA 之 多表聯合查詢
- Mybatis-Plus-Join(MPJ連表查詢)MyBatis
- Spring Data Jpa 的簡單查詢多表查詢HQL,SQL ,動態查詢, QueryDsl ,自定義查詢筆記SpringSQL筆記
- Spring Data JPA基本增刪改查和JPQL查詢(含完整程式碼和視訊連線)Spring
- mysql連表查詢出現資料重複MySql
- 連線查詢
- 如何使用Hibernate/JPA的JPQL/HQL查詢提取?
- Spring Data JPA 實現多表關聯查詢Spring
- mysql-分組查詢-子查詢-連線查詢-組合查詢MySql
- MySQL之連線查詢和子查詢MySql
- mysql查詢語句5:連線查詢MySql
- 單表查詢
- mysql資料庫連表查詢的幾種方法MySql資料庫
- Oracle:優化方法總結(關於連表查詢)Oracle優化
- Spring JPA聯表情況下的複雜查詢Spring
- spring data JPA 模糊查詢 --- 使用 LIKE --- 的寫法Spring
- Spring Boot中使用JPA構建動態查詢Spring Boot
- oracle 連線查詢Oracle
- SQL連線查詢SQL
- jpa 聯合查詢資料,查詢使用者資訊與部門資訊
- MySQL連線查詢驅動表被驅動表以及效能優化MySql優化
- mysql三表連線查詢以及百分數排序MySql排序
- 查詢 - 符號表符號