gpt4 book ai didi

hibernate - 在Hibernate HQL更新查询中使用联接

转载 作者:行者123 更新时间:2023-12-03 20:21:14 25 4
gpt4 key购买 nike

我有以下休眠映射:

 <class name="Domain.Roomreservation, Core" table="Reservationroom">
<id name="ID" unsaved-value="undefined">
<generator class="native">
<!--<param name="sequence">GLOBALSEQUENCE</param>-->
</generator>
</id>

<property name="FromTime" not-null="true" index="IDX_RESRAUM_FromTime" />
<property name="UntilTime" not-null="true" index="IDX_RESRAUM_UntilTime"/>

<many-to-one name="Booking" column="Book_ID" index="IDX_RAUMRES_BOOK" lazy="false"
class="Domain.Booking, Core" not-null="true" />
</class>


Reservationroom表如下所示:

ID         <pk>
Book_ID <fk>
FromTime
UntilTime
....
....


我的休眠查询看起来像:

String hql = "UPDATE Roomreservation as rr set rr.FromTime= 12:15" +
"Inner Join Booking b ON rr.Book_ID= b.ID " +
"Where b.ID = 95637";
IQuery query = CurrentSession.CreateQuery(hql);
int result = query.ExecuteUpdate();
Debug.WriteLine("Rows affected: " + result);


但是我总是得到 Error: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException

有人可以帮我如何使它正常工作吗?

最佳答案

您必须使用子查询而不是联接。大致如下:

UPDATE Roomreservation as rr set rr.FromTime= 12:15
WHERE rr.Book_ID IN (
SELECT b.id
FROM Booking b
WHERE b.id = 95637);


另外,根据 FromTime的类型,很可能应该以其他格式显示它。

关于hibernate - 在Hibernate HQL更新查询中使用联接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12034327/

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