A column definition list is required message when using @NamedStoredProcedureQuery in hibernate

StackOverflow https://stackoverflow.com/questions/22112695

  •  18-10-2022
  •  | 
  •  

Question

Am using the @NamedStoredProcedureQuery annotation to call a stored procedure from hibernate. My stored procedure returns fields from 2 tables and I can call it from postgresql as below:

select * from sp_select_employees t (id int, emp_name text, emp_department text)

I want to call that stored procedure from hibernate, but I get "A column definition list is required". I know its because hibernate is not including the

 t (id int, emp_name text, emp_department text)

part. How do I do this in hibernate? Below is my JPA class

@NamedStoredProcedureQuery(
 name = "SelectEmployees",
 resultClasses = EmployeeDetails.class,
 procedureName = "sp_select_employees"

)

public class Employees implements java.io.Serializable {
....
}

My code where I call hibernate

public List<EmployeeDetailsDTO> getEmployeeDetails()
{

  StoredProcedureQuery query = em.createNamedStoredProcedureQuery("SelectEmployees");
  final List<EmployeeDetails> searchResults = query.getResultList();

  final List<EmployeeDetailsDTO> results = new ArrayList<EmployeeDetailsDTO>();
  for (Campaigns searchResult : searchResults)
  {
     EmployeeDetailsDTO dto = new EmployeeDetailsDTO(searchResult);
     results.add(dto);
  }
  return results;     

}  
Was it helpful?

Solution

Change your procedure so it RETURNS TABLE or add OUT parameters, so you don't rely on sending a column definition list. Or use a native query in Hibernate.

A column definition list, and queries that return record, are PostgreSQL extensions that Hibernate does not support directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top