I am trying to call on a stored procedure from a db2 database using hibernate's entity manager and return the results as an object. I am using the @NamedStoredProcedureQuery annotation which does not seem to be found by hibernate. I am getting the error: "No @NamedStoredProcedureQuery was found with that name : Create_Division". Any ideas would be great.
beans:
<bean id="entityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="demoJPAUnit" />
<property name="packagesToScan">
<list>
<value>com.merchantBoarding.db2.queryObjects</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.archive.autodetection">class,hbm</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryBean" />
</bean>
Query output object:
@NamedStoredProcedureQuery(
name="Create_Division",
procedureName="MD.PMDBD017",
resultClasses = {CreateDivisionResult.class},
parameters={
@StoredProcedureParameter(name="IN_ENTY",mode=ParameterMode.IN,type=Integer.class),
@StoredProcedureParameter(name="IN_PARNT_ENTY",mode=ParameterMode.IN,type=Integer.class),
@StoredProcedureParameter(name="IN_ACTION",mode=ParameterMode.IN,type=String.class),
@StoredProcedureParameter(name="IN_ENTY_XREF",mode=ParameterMode.IN,type=String.class),
@StoredProcedureParameter(name="OUT_ENTY",mode=ParameterMode.OUT,type=Integer.class),
@StoredProcedureParameter(name="OUT_ID",mode=ParameterMode.OUT,type=String.class),
@StoredProcedureParameter(name="OUT_ENTY_XREF",mode=ParameterMode.OUT,type=String.class),
@StoredProcedureParameter(name="OUT_SQLCODE",mode=ParameterMode.OUT,type=Integer.class),
@StoredProcedureParameter(name="OUT_STATUS",mode=ParameterMode.OUT,type=String.class),
@StoredProcedureParameter(name="OUT_ERRORTEXT",mode=ParameterMode.OUT,type=String.class),
}
)
public class CreateDivisionResult implements Serializable {
@Id
public String OUT_ENTY;
public String OUT_ID;
public String OUT_ENTY_XREF;
public String OUT_SQLCODE;
public String OUT_STATUS;
public String OUT_ERRORTEXT;
}
DAO code:
StoredProcedureQuery query = manager.createNamedStoredProcedureQuery("Create_Division");
query.setParameter("IN_ENTY", 111);
query.setParameter("IN_PARNT_ENTY", 11111);
query.setParameter("IN_ACTION", "CREATE");
query.setParameter("IN_ENTY_XREF", "ED");
List<CreateDivisionResult> results = query.getResultList();
EDIT: So I added @Entity and that did fix the original error, but the output parameters still aren't mapping to the CreateDivisionResult object. I can only get each indiviual field with query.getOutputParameterValue. Is this just a restriction of JPA?
@NamedStoredProcedureQuery should be applied to Entity class or mapped class
Seems you are missing the @Entity in your 'CreateDivisionResult'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With