对于下面的设置,无法使用Spring JPA映射或获得所需的结果。我的存储过程如下:
CREATE PROCEDURE [dbo].[sp_name] AS BEGIN
SET NOCOUNT ON;
MERGE Products AS TARGET
USING UpdatedProducts AS SOURCE
ON (TARGET.ProductID = SOURCE.ProductID)
--When records are matched, update the records if there is any change
WHEN MATCHED AND TARGET.ProductName <> SOURCE.ProductName OR TARGET.Rate <> SOURCE.Rate
THEN UPDATE SET TARGET.ProductName = SOURCE.ProductName, TARGET.Rate = SOURCE.Rate
--When no records are matched, insert the incoming records from source table to target table
WHEN NOT MATCHED BY TARGET
THEN INSERT (ProductID, ProductName, Rate) VALUES (SOURCE.ProductID, SOURCE.ProductName, SOURCE.Rate)
--When there is a row that exists in target and same record does not exist in source then delete this record target
WHEN NOT MATCHED BY SOURCE
THEN DELETE
--$action specifies a column of type nvarchar(10) in the OUTPUT clause that returns
--one of three values for each row: 'INSERT', 'UPDATE', or 'DELETE' according to the action that was performed on that row
OUTPUT
DELETED.ProductID AS TargetProductID,
INSERTED.ProductID AS SourceProductID
END;
GO
@Repository类如下:
@Procedure(procedureName = "sp_name")
Map<String, Integer> callingSP();
进入以下异常:
Type不能为null;嵌套异常是java.lang.IllegalArgumentException: Type不能为null
请告诉我哪里出错了?
对于已经不存在作为表的结果集(因此在某处有@Entity
装饰类定义),技巧似乎是使用interface
用于在存储库中声明的@Query
装饰方法的结果。
给定存储过程的SQL设置…
use master;
go
create database StackOverflow;
go
use StackOverflow;
go
create table dbo.Products(
ProductID int not null,
ProductName nvarchar(50),
Rate float
);
go
create table dbo.UpdatedProducts(
ProductID int not null,
ProductName nvarchar(50),
Rate float
);
go
insert dbo.Products (ProductID, ProductName, Rate) values
(10, 'Ten', 10.10),
(20, 'Twenty', 20.20);
insert dbo.UpdatedProducts (ProductID, ProductName, Rate) values
(20, 'Twenty', 20),
(30, 'Thirty', 30);
go
select * from dbo.Products;
select * from dbo.UpdatedProducts;
go
收益率…
ProductID | ProductName | Rate | 10 | 十道明> | 20
---|---|---|
20 | 20.199999999999999 |