I have created stored procedure to get the data from database and converting the response to Java Object. I am having problem when I am trying to catch the response in custom Object. (NOTE : The example I have given is just for testing. I know there is simple way to perform the operation that I am trying to do it here. But it is just for explanation)
Stored Procedure :
CREATE PROCEDURE [dbo].[getVersionByName] @name nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * FROM [version] where [name] = @name
END
Version Entity :
@Entity
@NoArgsConstructor
@Data
@NamedStoredProcedureQuery(name = "Version.getVersionListedName"
, procedureName = "getVersionByName"
, parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN,name = "name", type = String.class)})
public class Version {
@Id
private Long id;
private String name;
}
Repository :
public interface VersionRepositoryExtended extends CrudRepository<Version, Long> {
@Procedure(procedureName = "getVersionByName")
public Version getVersionListedName(@Param("name") String name);
}
Question : If you see my stored procedure, there is a 'SELECT * ---' statement. I am trying to capture that output into my Java code as a return value. How can I do that ?
UPDATE
When I try to compile the code I get this below error : org.springframework.data.mapping.PropertyReferenceException: No property getVersionListedName found for type Version!
SELECT id, nameinstead ofSELECT *?findByNameand spring-data should generate the correct query for you based on the method name. See these docs for more details.