gpt4 book ai didi

java - hibernate :在更新中选择

转载 作者:行者123 更新时间:2023-12-04 06:12:28 27 4
gpt4 key购买 nike

我需要做这样的事情:

session.getTransaction().begin();
session.createQuery("update Pack p set p.book = (select b from Book b where ...) where p.id = :id")
.setLong("id", pack.getId())
.executeUpdate();
session.getTransaction().commit();

并有错误:
Exception occurred during event dispatching: 
org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile [java.util.Set(BookKeeper.db.Pack.book) : BookKeeper.db.Book]

但为什么? p.book有一个 Set<Book>类型,同 (select b from Book b where ...)必须返回。

最佳答案

如果你观察

p.book = (select b from Book b where ...)

选择应该返回一个唯一的值。如果没有,那么事情就会出错,因为你在右手边得到了一个 Set,而在左手边正在等待一本书。

这与 sql 语法非常相似。

关于java - hibernate :在更新中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7620115/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com