I am trying to call java sp , which is having select query like
Select a.name, b.age from tablea a, tableb b where a.emp=b.emp;
I am not sure how I can create Entity class for this and how to call.
I have done similar kind of coding where in java sp is taking one input and select query involve only one table.
please find demo code for same
Entity class
@NamedStoredProcedureQuery
(name="test",
procedureName="GETALLOP",
resultClasses=AfltModel.class,
parameters={
@StoredProcedureParameter(mode = ParameterMode.IN, name = "someinput", type = Integer.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "OUT_RETURN_CODE", type = Integer.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "OUT_RETURN_MESSAGE", type = String.class),
@StoredProcedureParameter(mode = ParameterMode.OUT, name = "OUT_MESSAGE_SOURCE", type = String.class)
})
@Entity
@Data
public class AfltModel {
@Id
@Column(name="FUTR.CORP_CUST_ID")
int corpcustid;
@Column(name="FUTR.AFLT_CUST_ID")
String afltcustid;
}
execution class
@Component
public class ServiceClass {
@Autowired
EntityManager entityManager;
public List<List<AfltAcctModel>> getdata(List<Integer> inputList) {
List<List<AfltAcctModel>> list = inputList.stream()
.map(id -> entityManager
.createNamedStoredProcedureQuery("test").setParameter("IN_ACCT_ID", id)
.getResultList())
.collect(Collectors.toList());
return list;
}
}
Please let me know how we can achieve same if we have to call java sp using entitymanger and sp is not taking any input and having multiple table as I mention above.