简体   繁体   English

Quarkus 延迟初始化

[英]Quarkus lazy initialize

I am getting the following error whenever I try to return all records using the rest method.每当我尝试使用 rest 方法返回所有记录时,都会收到以下错误。

Error:错误:

Internal Server Error Error handling e6059ae8-5970-4ac2-a1fa-7325768944bb-1, org.jboss.resteasy.spi.UnhandledException: javax.ws.rs.ProcessingException: RESTEASY008205: JSON Binding serialization error javax.json.bind.JsonbException: Unable to serialize property 'task' from model.Board Internal Server Error Error handling e6059ae8-5970-4ac2-a1fa-7325768944bb-1, org.jboss.resteasy.spi.UnhandledException: javax.ws.rs.ProcessingException: RESTEASY008205: JSON Binding serialization error javax.json.bind.JsonbException: Unable从 model.Board 序列化属性“任务”

org.hibernate.LazyInitializationException: Unable to perform requested lazy initialization [model.Board.task] - no session and settings disallow loading outside the Session org.hibernate.LazyInitializationException:无法执行请求的延迟初始化 [model.Board.task] - 没有 session 和设置不允许在 Z71C7AE294B7ABD866B3FB295B3B9E4 之外加载

first model第一个 model

@Entity
public class Task{

    @Id
    @Column(name = "TaskID")
    public Long taskId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "BoardID")
    public Board board;

    @Column(name = "Title")
    public String title;

    @Column(name = "Description", length = 1000)
    public String description;
}

second model第二 model

@Entity
public class Board{

    @Id
    @Column(name = "BoardID")
    public Long boardId;

    @OneToMany(mappedBy = "board")
    public List<Task> task = new ArrayList<>();;

    @Column(name = "Title")
    public String title;

    @Column(name = "Position")
    @NotNull
    public int position;
}

repository:存储库:

@ApplicationScoped
@Transactional
public class BoardRepository implements PanacheRepository<Board> {
}

example REST method示例 REST 方法

@Transactional
@ApplicationScoped
public class ExampleResource {

    @Inject
    BoardRepository boardRepository;

    @Inject
    TaskRepository taskRepository;

    @GET
    @Transactional
    public List<Board> getAll() {
        return boardRepository.listAll();
    }
}

The issue is, that during JSON serialization, it tries to serialize the task list which has a back reference to Board and something in that graph might not be initialized.问题是,在 JSON 序列化期间,它尝试序列化具有对Board的反向引用的task列表,并且该图中的某些内容可能未初始化。 Also, the serialization could lead to a cycle which can't be modeled directly in JSON so you have to resolve this somehow.此外,序列化可能会导致无法在 JSON 中直接建模的循环,因此您必须以某种方式解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM