Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPA&PostgreSQL:如何使用NamedNativeQuery注释调用存储过程_Java_Spring_Jpa_Stored Procedures - Fatal编程技术网

Java JPA&PostgreSQL:如何使用NamedNativeQuery注释调用存储过程

Java JPA&PostgreSQL:如何使用NamedNativeQuery注释调用存储过程,java,spring,jpa,stored-procedures,Java,Spring,Jpa,Stored Procedures,使用Postgresql 8.1、Spring 3.0、Hibernate 3.6。 我有一个方法可以调用一个不使用注释的存储过程,本质上是这样的 .... return (Integer) getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager em) { /

使用Postgresql 8.1、Spring 3.0、Hibernate 3.6。 我有一个方法可以调用一个不使用注释的存储过程,本质上是这样的

         ....
         return (Integer) getJpaTemplate().execute(new JpaCallback() {

            public Object doInJpa(EntityManager em) {                   
                // Query query = em.createNamedQuery("checkZone");
                Query query = em.createNativeQuery("select zoneArea from zoneArea(:pId, :zId)");
                query.setParameter("pId", p.getId());
                query.setParameter("zId", z.getId());

                try {
                    return query.getSingleResult(); // Integer expected
                } catch (NoResultException e) {
                    return 0;
                }
            }
        });
    ....
如何使用注释实现这一点,我的尝试是无效的

@NamedNativeQueries({
@NamedNativeQuery(
    name = "checkZone",
    query = "select zoneArea from zoneArea(:pId, :zId)",
    hints = {
        @QueryHint(name = "org.hibernate.callable", value = "true")
    },
    resultSetMapping = "scalar",
    resultClass = Integer.class)})
@SqlResultSetMapping(name="scalar",columns=@ColumnResult(name="result"))
@Entity
这是个例外

Caused by: org.postgresql.util.PSQLException: This statement does not declare an OUT parameter.  Use { ?= call ... } to declare one.
at org.postgresql.jdbc2.AbstractJdbc2Statement.registerOutParameter(AbstractJdbc2Statement.java:1849)
at org.postgresql.jdbc3.AbstractJdbc3Statement.registerOutParameter(AbstractJdbc3Statement.java:1513)
at org.hibernate.dialect.PostgreSQLDialect.registerResultSetOutParameter(PostgreSQLDialect.java:335)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1713)
at org.hibernate.loader.Loader.doQuery(Loader.java:801)
我有工作代码,但想让这与注释,任何想法赞赏工作