【问题标题】:Calling & reading results from a procedure in hibernate从休眠中的过程调用和读取结果
【发布时间】:2013-10-18 08:06:37
【问题描述】:

我正在尝试在休眠状态下运行下面提到的过程,但我不知道该怎么做?

DELIMITER $$
CREATE PROCEDURE LoadData(
aircraft_id1 bigint, provider_fl_id varchar(32), city1 varchar(32), time1 timestamp, fare decimal(10,4), 
city2 varchar(32), time2 timestamp)
        BEGIN
                DECLARE flId bigint default 0;
                DECLARE rId int default 0;
                DECLARE r_id bigint default 0;
                DECLARE seat_no int default 0;
                SET rId=-1;
                SET flId=-1;
                SET r_id=-1;
                SET seat_no=-1;
                SELECT flight_id into flId from flight_schedule where
aircraft_id=aircraft_id1 and
                ((from_datetime > time1 and from_datetime < time2) or (to_datetime >
time1 and to_datetime < time2)) limit 1;
                if flId < 0 THEN
                    Select count(*) into rId from route where source=city1 and destination=city2;
                        if rId < 1 THEN
                            Insert into route(source,destination) values(city1,city2);
                        end if;                     
                        Select route_id into r_id from route where source=city1 and destination=city2;
                        Select seats into seat_no from aircraft where aircraft_id=aircraft_id1;
                        Insert into flight_schedule(route_id, aircraft_id, provider_flight_id,
                            from_datetime, to_datetime, seats, fare) values(r_id,
                                aircraft_id1, provider_fl_id, time1, time2, seat_no ,fare);
                Select "Success" as Result;
                else Select "Failure" as Reuslt;
                end if;
        END $$
DELIMITER ;

我正在使用下面的代码,但它不起作用。

HibernateUtil
                            .getSession()
                            .createSQLQuery(
                                    "CALL (:aircraftId, :providerFlightId, :city1,:time1,:fare,:city2,:time2)")
                            .addEntity(String.class)
                            .setParameter("aircraftId", row[0])
                            .setParameter("providerFlightId", row[1])
                            .setParameter("city1", row[2])
                            .setParameter("time1", row[3])
                            .setParameter("fare", row[4])
                            .setParameter("city2", row[5])
                            .setParameter("time2", row[6]);

我想我也必须调用 addEntity() 但我不知道哪个类会起作用? 任何链接、帮助或参考都将是可观的。 谢谢。

【问题讨论】:

    标签: mysql hibernate hql procedure


    【解决方案1】:

    我已经使用 createSqlQuery 方法解决了我的问题,并在不使用 addEntity 或 setParameter 的情况下简单地运行它。 mysql 终端上显示的结果也应该是结果集的列表类型。 如果您需要更多说明,请告诉我。 谢谢。

    【讨论】:

      猜你喜欢
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      • 1970-01-01
      • 2018-06-18
      相关资源
      最近更新 更多