我正在尝试在休眠中运行下面提到的过程,但我不知道该怎么做?
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() 但我不知道哪个类会起作用?任何链接、帮助或参考都将是可观的。谢谢你。