今天的问候..
请给我支持。 我是Jpa的新手,用@NamedStoredProcedureQuery调用procuder,但是我的代码给出了Exception as @NamedStoredProcedureQuery NamedQuery of name:procuder not found
我的代码是:=
@NamedStoredProcedureQuery(name = "TEST1",procedureName = "TEST1",parameters = { @StoredProcedureParameter(name = "P_CODE", mode = ParameterMode.IN, type = String.class), @StoredProcedureParameter(name = "P_DATE", mode = ParameterMode.IN, type = String.class), @StoredProcedureParameter(name = "P_CURSOR", mode = ParameterMode.REF_CURSOR, type = void.class), })
public class AnotherWayOfCallingProcedure implements Serializable
{
private static final String PERSISTENCE_UNIT_NAME = "todos";
private static EntityManagerFactory factory;
public static void main(String arg[]) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
StoredProcedureQuery addBookNamedStoredProcedure = em.createNamedStoredProcedureQuery("TEST1");
addBookNamedStoredProcedure.setParameter("P_CODE", "5000");
addBookNamedStoredProcedure.setParameter("P_DATE", "5/3/2017");
// Stored procedure call
List createdBookId = addBookNamedStoredProcedure.getResultList();
em.close();
}
}
和persistence.xml
是
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="todos" transaction-type="RESOURCE_LOCAL">
<class>com.app.IptAnchorageAreaMaster</class>
<class>com.app.AnotherWayOfCallingProcedure</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@192.168.6.147:1521:orcl" />
<property name="javax.persistence.jdbc.user" value="aaa_kkk" />
<property name="javax.persistence.jdbc.password" value="aaa" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="none" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
</persistence>