如何转换Hibernate查询到标准

问题描述 投票:0回答:1

我已经写了一个查询通过多个实体循环,并想将它转化成一种超脱的条件查询。不知道如何做到这一点的多个表

StringBuilder queryString = new StringBuilder("from ");
    queryString.append(Entity).append(" e where e.specificationId in (:ids) 
       and not exists ( select 1 from Association a where "
           + "a.sourceReference = e.reference )").append("order by    
                e.displayOrder");
hibernate hql criteria
1个回答
0
投票

你可以使用Spring JPA。

@NoRepositoryBean
public interface GenericRepository<T extends Content<T>> extends JpaRepository<T, Long>

@Query("select e from #{#entityName} e where e.specificationId in (?) and not exists ( select 1 from Association a where a.sourceReference = e.reference ) order by e.displayOrder", nativeQuery=true)
public void T findByIds(List<Long> ids);

您将创建为每种类型的一个接口并实现GenericRepository。

例如:

@Repository
public interface AbcRepository extends GenericRepository<Abc>{

}

请参阅:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/

© www.soinside.com 2019 - 2024. All rights reserved.