首页 > 代码库 > JPA查询

JPA查询

1. getCriteriaBuilder

技术分享
CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
getCriteriaBuilder

 

2. createQuery

技术分享
CriteriaQuery<TrainOrder> query = builder.createQuery(TrainOrder.class);
createQuery

 

3. Compose SQL

    1) table

技术分享
Root table = query.from(TrainOrder.class);
query.from

 

    2) Condition

List<Predicate> predicate = new ArrayList<Predicate>();        predicate.add(builder.gt(table.get("trainNumber"), trainNumber));        predicate.add(builder.gt(table.get("seriaryNumber"), seriaryNumber));        Predicate[] condition = new Predicate[predicate.size()];

 

    3) SQL

技术分享
query.where(builder.and(predicate.toArray(condition)));
query.where

 

4. result

技术分享
TypedQuery<TrainOrder> result =                 getEntityManager().createQuery(query);                return (TrainOrder) result.getResultList();
result.getResultList

 

JPA查询