本文介绍了HQL:结合“插入...选择”具有固定的参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有HQL语句:

  insert into Item(ost,value,comments,startTime,endTime,proposedBy)
从项目si中选择si.ost,si.value,si.comments,si.endTime,si.endTime,u
,用户u
其中si.ost =?和u.id =?

它如何被修改为使用 ost startTime 列,同时从选择

解决方案

我不知道最后的答案。我使用的是NH 3.2,并且我能够使它工作

  var hql = @INSERT INTO EventFacility(Facility,Event ,所有者,职位)
SELECT f,:evt,:own,:设备f的位置,其中f.Id IN(105,109,110);

var @event = Session.Get< Event>(351931);
var query = Session.CreateQuery(hql)
.SetInt32(position,0)
.SetEntity(evt,@event)
.SetEntity(own ,@ event.Owner);

var x = query.ExecuteUpdate();
Assert.AreEqual(3,x);

在这个例子中,我需要创建一个新的EventFacility对象。几乎所有你在这里看到的领域。事件实体有另一个实体,所有者挂起它。

I have HQL statement:

insert into Item (ost, value, comments, startTime, endTime, proposedBy) 
select si.ost, si.value, si.comments, si.endTime, si.endTime, u 
from Item si, User u 
where si.ost = ? and u.id = ?

How could it be modified to use parameters' values for ost and startTime columns while taking other columns from select?

解决方案

I don't know about that last answer. I am using NH 3.2 and I was able to get this to work

var hql = @"INSERT INTO EventFacility (Facility, Event, Owner, Position) 
SELECT f, :evt, :own, :position from Facility f where f.Id IN (105, 109, 110)";

var @event = Session.Get<Event>(351931);
var query = Session.CreateQuery(hql)
                .SetInt32("position", 0)
                .SetEntity("evt", @event)
                .SetEntity("own", @event.Owner);

var x = query.ExecuteUpdate();
Assert.AreEqual(3, x);

In this example I needed to create a new EventFacility object. With pretty much all the fields you see here. The Event entity has another entity, Owner hanging off of it.

这篇关于HQL:结合“插入...选择”具有固定的参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 12:55