本文介绍了在 Hibernate HQL 更新查询中使用连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下休眠映射:

 <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
....
....

我的 Hibernate 查询如下所示:

My Hibernate Query looks like:

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);

但我总是收到错误:NHibernate.Hql.Ast.ANTLR.QuerySyntaxException

有人可以帮助我如何让它工作吗?

Can someone help me how to get this to work?

推荐答案

你必须使用子查询而不是连接.大致如下:

You have to use subquery instead of join. Roughly as follows:

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 的类型,它很可能应该以其他格式呈现.

Additionally depending about type of FromTime it is likely that it should be presented in some other format.

这篇关于在 Hibernate HQL 更新查询中使用连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 23:52