HQL not working with H2 -
i implementing unit test using h2 embedded database. when insert entry in table, able retrieve entry using native sql query, not hql query. find primary key works through jpa entitymanager interface. using hibernate persistence provider.
configuration:
<bean id="hibernatejpavendoradapter" class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter" p:showsql="true" p:generateddl="false" p:databaseplatform="org.hibernate.dialect.h2dialect" /> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean" p:datasource-ref="datasource" p:jpavendoradapter-ref="hibernatejpavendoradapter" p:persistenceunitname="amgsadapter" p:packagestoscan="com.hcsc.amgs.adapter.domaindto"> <property name="jpaproperties"> <props> <prop key="hibernate.hbm2ddl.auto">create</prop> </props> </property> <property name="jpapropertymap"> <map> <entry key="hibernate.ejb.interceptor" value="com.hcsc.amgs.adapter.dao.hibernate.interceptor.auditablefieldinterceptor" /> </map> </property> </bean>
test case:
@test @transactional(value="transactionmanager",propagation = propagation.required) public void getvaspolicymatchestest() { application application = testdatacreationutil.createapplication(); entitymanager.persist(application.getx834enrollmentapplicationtransaction()); entitymanager.persist(application); list<application> matches = new arraylist<application>(); query q = simplequeryhql(); matches= q.getresultlist(); application findapp = entitymanager.find(application.class, application.getid()); // works assert.asserttrue(matches.size() > 0); } private query simplequeryhql() { return entitymanager.createquery("select app application app", application.class); } private query simplequerysql() { return entitymanager.createnativequery("select * application", application.class); }
no exceptions thrown, test case fails simplequeryhql() , passes simplequerysql()
Comments
Post a Comment