Reputation: 533
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!
Upvotes: 1
Views: 3175
Reputation: 21
true for Oracle DB
@Entity
@NoArgsConstructor
@Data
@NamedStoredProcedureQuery(name = "Version.NamedQuery_getVersionListedName"
, procedureName = "getVersionByName"
, parameters = {
@StoredProcedureParameter(
mode = ParameterMode.IN,
name = "name",
type = String.class),
@StoredProcedureParameter(
mode = ParameterMode.REF_CURSOR,
name = "OUT",
type = Class.class)
})
public class Version {
public static final String NamedQuery_getVersionListedName = "getVersionListedName";
@Id
private Long id;
private String name;
}
public interface VersionRepositoryExtended extends CrudRepository<Version, Long> {
@Procedure(name = Version.NamedQuery_getVersionListedName)
public Version getVersionListedName(@Param("name") String name);
}
Upvotes: 2