I tried to get the data from the postgresSql function, I used this example here
Below the mapping class with IN/OUT data:
@XmlType(name="AccountRR")
@NamedStoredProcedureQuery
(
name="getAccountMapping",
procedureName="accountFunction",
parameters = {
@StoredProcedureParameter(name="in_route", mode=ParameterMode.IN, type=String.class),
@StoredProcedureParameter(name="in_round", mode=ParameterMode.IN, type=String.class)
},
resultSetMappings={"AccountRouteRoundMapping"}
)
@SqlResultSetMapping
(
name = "AccountRouteRoundMapping",
entities =
{
@EntityResult
(
entityClass = AccountRouteRound.class,
fields =
{
@FieldResult(name = "name", column = "name"),
@FieldResult(name = "address_1", column = "address_1"),
@FieldResult(name = "address_2", column = "address_2")
[....]
}
)
}
)
public class AccountRouteRound {.............}
Below the class where I call createNamedStoredProcedureQuery
public static List<Account> getAccount(....)
{
em.getTransaction().begin();
StoredProcedureQuery spq = em.createNamedStoredProcedureQuery("getAccountMapping");
List CustomerRRDList = spq.getResultList();
em.getTransaction().commit();
}
I received this error :
**Caused by: java.lang.IllegalArgumentException: No @NamedStoredProcedureQuery was found with that name : getAccountMapping**
Where should I insert the annotation? What is wrong ?
Thank you
Fixed. I changed my code :
public List<Account> getAccountFromStoreProcedure(EntityManager em, String routeCode, String round)
{
StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery("getAccountFunction");
// set parameters
storedProcedure.registerStoredProcedureParameter("in_route", String.class, ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter("in_round", String.class, ParameterMode.IN);
storedProcedure.setParameter( "in_route",routeCode);
storedProcedure.setParameter( "in_round",round);
storedProcedure.executeUpdate();
List<Object> objectList = storedProcedure.getResultList();
for (int i = 0; i< objectList.size(); i++) {
Account currAccount = new Account ((Object[]) objectList.get(i));
tmpList.add(currAccount);
System.out.println("currAccount : " + currAccount.toString()); }
}
On the Account constructor :
public Account (Object[] fromStoredProcedure) {
super();
this.name = (String)fromStoredProcedure[0];
this.address_1 = (String)fromStoredProcedure[1];
this.address_2 = (String)fromStoredProcedure[2];
}