Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate No @NamedStoredProcedureQuery was found with that name

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?

like image 403
Lezorte Avatar asked Feb 05 '23 17:02

Lezorte


1 Answers

@NamedStoredProcedureQuery should be applied to Entity class or mapped class

Seems you are missing the @Entity in your 'CreateDivisionResult'

like image 92
kuhajeyan Avatar answered Feb 13 '23 03:02

kuhajeyan