我有一个尝试使用Hibernate从DB返回字符串列表的过程
public List<String> getErrorMessage(int incidentID){
List<String> returnObj = new ArrayList<String>();
StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery("dbo.DisplayMessage")
.registerStoredProcedureParameter("IncidentID", Integer.class, ParameterMode.IN)
.setParameter("IncidentID", incidentID);
boolean status = storedProcedure.execute();
List<Object[]> storedProcedureResults = storedProcedure.getResultList();
if(storedProcedureResults==null || storedProcedureResults.size()==0)
{
return null;
}
for(Object[] row: storedProcedureResults) {
returnObj.add((String)row[0]);
}
return returnObj;
}
但是,我收到错误说 -
java.lang.String cannot be cast to [Ljava.lang.Object;
存储过程仅返回字符串列表。如何在函数中返回它?