我有一个 SQL Server 2005 存储过程,可以将一堆行从一个表移动到另一个表。我正在使用spring的StoredProcedure
类来调用该过程。这是代码:
public class MigracionPagoMasivoNormalATemporalStoredProcedure extends StoredProcedure {
...
public Long ejecutar(final Long idPagoMasivo) {
final Map<String, Object> inputs = new HashMap<String, Object>();
Map<String, Object> outs = new HashMap<String, Object>();
inputs.put(ID_UPLOAD_HEADER, idPagoMasivo);
inputs.put(ID_UPLOAD_HEADER_TEMPORAL, 0);
try {
outs = super.execute(inputs);
return Long.valueOf((Integer) outs.get(ID_UPLOAD_HEADER_TEMPORAL));
} catch (final Exception e) {
// TODO dcalderon: Controlar excepciones
e.printStackTrace();
}
return new Long(0);
}
}
该过程被成功调用,并且完全按照它的意图进行。问题是我必须在之后查询迁移的行。这次我使用休眠。两种方法都可以很好地分开,但是我假设存储过程以某种方式锁定了表并阻止了查询的执行。
这是存储过程:
CREATE PROCEDURE dbo.SP_PM_MIGRARLOTENORMALATEMPORAL(@ID_UPLOAD_HEADER int, @ID_UPLOAD_HEADER_TEMPORAL int OUTPUT)
AS
BEGIN
BEGIN TRANSACTION
/* Se migra el pago masivo de la tabla normal a la tabla temporal*/
INSERT INTO UPLOAD_HEADER_TEMPORAL (id_upload_header, ...)
SELECT [id], ...
FROM UPLOAD_HEADER WHERE [id] = @ID_UPLOAD_HEADER
SET @ID_UPLOAD_HEADER_TEMPORAL = (SELECT SCOPE_IDENTITY())
/* Se migra el detalle del pago masivo de la tabla normal a la temporal */
INSERT INTO UPLOAD_RECORD_TEMPORAL (id_header, ...)
SELECT @ID_UPLOAD_HEADER_TEMPORAL, ... FROM UPLOAD_RECORD
WHERE id_header = @ID_UPLOAD_HEADER
/* Se hace update al estado del detalle en la tabla temporal */
UPDATE UPLOAD_RECORD_TEMPORAL SET status = 0 WHERE id_header = @ID_UPLOAD_HEADER_TEMPORAL
COMMIT TRANSACTION
END
我的问题是,如何执行查询,恢复表的锁?(我已经调试了代码,我知道它被锁定在查询中)。谢谢。