java - Get column names in result set Spring data JPA -
i have simple procedure lists out users. using @namedstoredprocedurequeries
procedure declaration , used entitymanager.createnamedstoredprocedurequery
storedprocedurequery
.
it returns result need column name know value column.
my code goes this
entity class
@entity @namedstoredprocedurequeries({ @namedstoredprocedurequery(name = "sgetuserlist", procedurename = "sgetuserlist", parameters = { @storedprocedureparameter(mode = parametermode.in, name = "user_id", type = integer.class) }) }) public class user { @id @generatedvalue(strategy = generationtype.auto) private integer id; private string name; private string email; //getters , setters }
custom repositoty
public interface userrepositorycustom { list<?> testproc() ; }
repository
public interface userrepository extends jparepository<user, long>, userrepositorycustom{ }
repository implementation
public class userrepositoryimpl implements userrepositorycustom{ @persistencecontext entitymanager em; public list<object> testproc() { storedprocedurequery q = em.createnamedstoredprocedurequery("sgetuserlist"); q.setparameter("user_id", 1); list<object> res = q.getresultlist(); return res; } }
i need result column names.
i'm not sure understand trying here. if want users using spring data shouldn't implementing userrepository. spring data you.
in fact jparepository has method need.
list<user> findall();
you can call list of users , won't need worry column names.
just inject repository need , call method users:
@autowire userrepository userrepository; list<users> allusers = userrepository.findall();
edit: if there particular reason want use stored procedures though there spring data way of doing without implementing userrepository yourself. can defining following method:
public interface userrepository extends jparepository<user, long>{ @procedure(name = "sgetuserlist") list<user> sgetuserlist(@param("user_id") integer userid); }
again there shouldn't issue resolving column names method.
Comments
Post a Comment