2016-11-24 4 views
0
으로 쿼리 작성

QueryDSL에서 쿼리를 작성 중입니다. 엔티티와 하위 클래스 엔티티가 같은 열을 가지고 있습니다. 하나의 JPAQuery 만 사용하여 두 엔티티 모두에 동일한 쿼리를 사용하고 싶습니다.QueryDSL 서브 클래스

여기 내 조직입니다.

@Entity 
public class Region { 

    @Id 
    private Integer id; 

} 

@Entity 
public class RegionTemp extends Region {} 

queryer

@Component 
public class RegionQueryer { 

    @PersistenceContext 
    private EntityManager mysqlEntityManager; 

    QRegion qRegion = QRegion.region; // ??? 

    public Integer loadLastId() { 

     return new JPAQueryFactory(mysqlEntityManager) 
       .select(qRegion.id) 
       .from(qRegion) 
       .orderBy(qRegion.id.desc()).fetchFirst(); 
    } 
} 

답변

0

내 코드입니다. 이 샘플. 단일 쿼리를 사용하려는 경우 간단한 저장소를 사용하십시오. 쉽게 찾기, 삭제, 저장합니다. JPA Tutorial을 검색합니다.

@Override 
public List<CompanyInformaion> findCompanyInformationList(String language, Association association) { 
    QCompanyInformaion qCompanyInformaion = QCompanyInformaion.companyInformaion; 
    QCompany qCompany = QCompany.company; 

    EntityManager em = entityManagerFactory.createEntityManager(); 
    JPAQuery jpaQuery = new JPAQuery(em); 

    List<CompanyInformaion> infos = jpaQuery.from(qCompanyInformaion) 
      .where(qCompanyInformaion.language.eq(language) 
        .and(qCompanyInformaion.company.in(new JPASubQuery().from(qCompany) 
          .where(qCompany.association.eq(association)).list(qCompany)))) 
      .orderBy(qCompanyInformaion.companyName.asc()).list(qCompanyInformaion); 

    return infos; 
}