相关疑难解决方法(0)

如何在JPA中的两列上运行SUM等聚合函数并显示其结果?

我是JPA的新手.所以我的问题对某些人来说应该是如此简单.

下面是SQL中的简单查询,我想将其转换为JPA.我已经有一个实体类叫TimeEnt.

SELECT 
     SUM(TimeEntryActualHours) as UnBilledHrs,
     SUM (TimeEntryAmount) as UnbilledAmount
FROM TimeEnt WHERE MatterID = 200
Run Code Online (Sandbox Code Playgroud)

java orm jpa java-ee-6 jpa-2.0

28
推荐指数
3
解决办法
6万
查看次数

如何使用spring-data-jpa检索聚合函数查询

我正在使用Spring数据jpa 1.2,我无论如何都找不到像下面那样检索聚合查询结果.

select count(v), date(v.createTimestamp) from UserEntity v
    group by date(v.createTimestamp)
Run Code Online (Sandbox Code Playgroud)

哪个与原生JPA完美配合

@Entity()
public class UserEntity {

   @Id
   private long id;
   .
   .
   @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
   private Timestamp createTimestamp;

}
Run Code Online (Sandbox Code Playgroud)

我的JPA存储库是

public interface UserRepository extends JpaRepository<UserEntity, Long>, 
      JpaSpecificationExecutor<UserEntity> {
}
Run Code Online (Sandbox Code Playgroud)

那么如何才能进行聚合查询抛出Spring数据,我在文档中找不到任何内容

java spring jpa spring-data spring-data-jpa

4
推荐指数
2
解决办法
2万
查看次数

使用JpaSpecificationExecutor时使用QueryHint

我使用spring数据和JpaSpecificationExecutor::findAll方法来获取模型。调用此方法时如何使用查询提示?
上面的源代码工作正常,但是我无法为我的JPA提供程序(在我的情况下为EclipseLink)设置QueryHint。

@Repository
public interface ProductRepository extends JpaRepository<Product, Integer>, JpaSpecificationExecutor<Product> {
}

@Service
public class ProductService {

    @Autowired
    private ProductRepository productRepository;

    public List<Product> findByTitle(String locale, String titleToSearch) {
        return productRepository.findAll((Root<ProductCategory> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
            return builder.equal(builder.function("jsonb_extract_path_text", String.class, root.<String>get("title"), builder.literal(locale)), titleToSearch);
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

以上是我使用spring-data使用查询提示的方式,

@Repository
public interface ProductRepository extends JpaRepository<Product, Integer>, JpaSpecificationExecutor<Product> {

    @QueryHints(value = {
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH_TYPE, value = "JOIN"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "p.productCategory"),
        @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "p.productFileList")
    }, …
Run Code Online (Sandbox Code Playgroud)

java specification-pattern eclipselink spring-data

2
推荐指数
1
解决办法
5060
查看次数