JPA 2.1 error : No @NamedStoredProcedureQuery was found with that name :

JPA 2.1 error : No @NamedStoredProcedureQuery was found with that name :

我尝试从 postgresSql 函数中获取数据,我使用了这个示例 here

在 class 与 IN/OUT 数据的映射下方:

@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 {.............}

在我调用 createNamedStoredProcedureQuery

的 class 下方
public static List<Account> getAccount(....)
{
    em.getTransaction().begin();
    StoredProcedureQuery spq = em.createNamedStoredProcedureQuery("getAccountMapping");
    List CustomerRRDList = spq.getResultList();
    em.getTransaction().commit();
}

我收到此错误:

**Caused by: java.lang.IllegalArgumentException: No @NamedStoredProcedureQuery was found with that name : getAccountMapping**

我应该在哪里插入注释?怎么了?

谢谢

我试过这种方法,它工作正常,但是当函数发回一个列表时,我不知道如何获取所有组件并将其插入到列表中:

StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery("getAccountMapping");
// set parameters
storedProcedure.registerStoredProcedureParameter("in_route",        String.class,     ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter("in_round",        String.class,     ParameterMode.IN);
storedProcedure.registerStoredProcedureParameter("name",            String.class,     ParameterMode.OUT);
storedProcedure.registerStoredProcedureParameter("address_1",       String.class,     ParameterMode.OUT);
storedProcedure.registerStoredProcedureParameter("address_2",       String.class,     ParameterMode.OUT);
[...........]
storedProcedure.setParameter( "in_route",routeCode);
storedProcedure.setParameter( "in_round",round);
storedProcedure.execute();
String name = (String)storedProcedure.getOutputParameterValue("name");
[.......]
    System.out.println("TEST : "+name);

已修复。 我更改了代码:

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()); }
    }

A​​ccount 构造函数上:

public Account (Object[] fromStoredProcedure) {
        super();
        this.name           = (String)fromStoredProcedure[0];
        this.address_1      = (String)fromStoredProcedure[1];
        this.address_2      = (String)fromStoredProcedure[2];           
    }