小编non*_*ono的帖子

弹簧数据 JPA。子实体的分页

我将 Spring Data JPA 与 Spring Boot 版本 1.3.6.RELEASE 与内存数据库一起使用。

我想知道如何从父实体对子实体进行分页。将 fetch 设置为LAZY对我来说不是解决方案。

这是用例:

  1. Parent与 Child entity有一个单向oneToMany 关系。
  2. 一个ParentChild数量可以达到100,000(LAZY不是解决方案)
  3. 我不想获取所有孩子来进行分页(出于 CPU 和内存原因)

这是一个代码示例:

@Entity
public class Parent{
    @Id
    private Integer id;

    @OneToMany
    private List<Child> childs;
}

@Entity
public class Child {
    @Id
    private Integer id;
}

public interface ParentRepository extends JpaRepository<Parent, Integer>{}
public interface ChildRepository extends JpaRepository<Child, Integer>{}
Run Code Online (Sandbox Code Playgroud)

我在父存储库中尝试过这个失败:

Page<Child> findById(int id, Pageable pageable);
Run Code Online (Sandbox Code Playgroud)

这将返回父实体,而不是子实体。

知道如何做到这一点吗?

java jpa one-to-many spring-data spring-boot

6
推荐指数
1
解决办法
5104
查看次数

Keycloak Spring boot configuration

I'm trying to configure Spring Boot and Keycloak for SSO. I've created a basic AngularJS application that do some requests to the Spring boot backend. using this

The Angular app is working fine and now I'm trying to follow the new Spring Boot Keycloak apdater docuementation here

This is my keycloak.json that is in the WEB-INF folder.

{
  "realm": "my-backend",
  "bearer-only": true,
  "realm-public-key": "MIIB...",
  "auth-server-url": "http://localhost:8180/auth",
  "ssl-required": "external",
  "resource": "my-backend",
  "principal-attribute": "preferred_username",
  "credentials": {
    "secret": "a75f55ca-8174-4072-8c60-b545c9ebf7e1"
}
Run Code Online (Sandbox Code Playgroud)

Here is my …

spring-security spring-boot keycloak

5
推荐指数
2
解决办法
6106
查看次数