小编hyn*_*iia的帖子

Spring Jpa Projection接口发生Boolean类型错误

问:为什么 JPA Projection 无法转换Mysql bit(1)Java Boolean

Projection type must be an interface!当Mysqlbit(1)类型映射到Java类型时, Spring Jpa Projection出现错误Boolean

Jpa 将实体类中的布尔列转换为 Mysql 表中的位(1)列。

如果我将getIsBasicPlanInfoProjection 接口中的类型更改IntegerBoolean,则不起作用。为什么会出现错误呢?

JPA 存储库

@Query(nativeQuery=true, value="select true as isBasic from dual")
ProductOrderDto.PlanInfoProjection findPlanInfoById(Long id);
Run Code Online (Sandbox Code Playgroud)

投影接口

public class ProductOrderDto {

    @Getter
    public static class PlanInfo {
        private Boolean isBasic;

        public PlanInfo(PlanInfoProjection projection) {
            // this.isBasic = projection.getIsBasic(); //<-- I want to use like this.
            if (projection.getIsBasic() == …
Run Code Online (Sandbox Code Playgroud)

mysql spring boolean projection spring-data-jpa

12
推荐指数
1
解决办法
3622
查看次数

Spring @Cachable method within the same class (self-invocation, proxy issue) - What is the best way to solve it?

I'm trying to call a @Cacheable method from within the same class.

And it didn't work. Because of:

In proxy mode (the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation (in effect, a method within the target object that calls another method of the target object) does not lead to actual caching at runtime even if the invoked method is marked with @Cacheable. Consider using the aspectj mode in this case. Also, …

spring caching aspectj ehcache self-invoking-function

6
推荐指数
0
解决办法
6291
查看次数

Spring JPA 批量更新插入很慢(1,000 个实体花了 20 秒)

当我尝试更新插入测试数据(1,000 个实体)时,花了1m 5s。

\n

所以我看了很多文章,然后我把处理时间减少到20秒

\n

但它对我来说仍然很慢,我相信有比我使用的方法更多的好的解决方案。有没有人有好的做法来处理这个问题?

\n

我还想知道哪个部分使它变慢?

\n
    \n
  1. 持久化上下文
  2. \n
  3. 附加选择
  4. \n
\n

谢谢你!

\n
\n

@实体类

\n

该实体类是从用户手机中收集到用户步行步数的健康数据。

\n

PK为userIdrecorded_atrecorded_atPK来自请求数据)

\n
@Getter\n@NoArgsConstructor\n@IdClass(StepId.class)\n@Entity\npublic class StepRecord {\n    @Id\n    @ManyToOne(targetEntity = User.class, fetch = FetchType.LAZY)\n    @JoinColumn(name = "user_id", referencedColumnName = "id", insertable = false, updatable = false)\n    private User user;\n\n    @Id\n    private ZonedDateTime recordedAt;\n\n    @Column\n    private Long count;\n\n    @Builder\n    public StepRecord(User user, ZonedDateTime recordedAt, Long count) {\n        this.user = user;\n …
Run Code Online (Sandbox Code Playgroud)

spring jpa bulkinsert batch-processing

5
推荐指数
1
解决办法
5755
查看次数