Hades with OpenJPA, Pageable queries work with Unit Test but not with Web App
Added by Jeffrey Cutler 6 months ago
I'm working on a web app running on Tomcat 6, JDK 6, OpenJPA 1.2.1, Spring 2.5, Hades 1.1.1.
Hades is working very well for my unit tests and is saving me a lot of coding! In the unit tests the query is created successfully and performs as expected. However, when I try and start the webapp I get the following error on creation of my DAO bean:
Caused by: org.synyx.hades.dao.query.QueryCreationException: Could not create query for public abstract java.util.List net.jpcutler.persist.FundingDAO.findActive(org.synyx.hades.domain.Pageable)! Reason: Cannot use Pageable parameter in query methods with your persistence provider!
at org.synyx.hades.dao.query.QueryCreationException.create(QueryCreationException.java:53)
at org.synyx.hades.dao.query.NamedHadesQuery.lookupFrom(NamedHadesQuery.java:87)
at org.synyx.hades.dao.query.QueryLookupStrategy$2.resolveQuery(QueryLookupStrategy.java:53)
at org.synyx.hades.dao.query.QueryLookupStrategy$3.resolveQuery(QueryLookupStrategy.java:78)
at org.synyx.hades.dao.query.QueryMethod.<init>(QueryMethod.java:104)
at org.synyx.hades.dao.orm.GenericDaoFactory$QueryExecuterMethodInterceptor.<init>(GenericDaoFactory.java:358)
at org.synyx.hades.dao.orm.GenericDaoFactory.getDao(GenericDaoFactory.java:175)
at org.synyx.hades.dao.orm.GenericDaoFactoryBean.getObject(GenericDaoFactoryBean.java:95)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:121)
If the unit test can create the dao successsfully, shouldn't the container be able to do so as well?
Any help would be greatly appreciated! Below are the relevant parts of my classes and tests.
Thanks,
Jeff
My entity class is Funding with the following named query:
1 @NamedQuery(name = "Funding.findActive", query = "SELECT f FROM Funding f WHERE f.lock.lockCde=3 AND f.status.statusCde=1"),
My DAO class, FundingDAO:
1 public interface FundingDAO extends GenericDao<Funding, Integer>, LookupDAO {
2 public List<Funding> findActive();
3 public List<Funding> findActive(Pageable page);
4 }
My unit test, FundingDAOTest:
1 public void testFindActivePageable() {
2 System.out.println("findActivePageable"); // Initialize Expected Result
3 List expResult = Arrays.asList(new Funding[]{new Funding(3),new Funding(4)});
4
5 PageRequest pager = new PageRequest(1,2);
6 // Get list from database
7 List result = dao.findActive(pager);
8 assertArrayEquals(expResult.toArray(), result.toArray());
9 }
Replies
RE: Hades with OpenJPA, Pageable queries work with Unit Test but not with Web App
-
Added by Oliver Gierke 6 months ago
Hey Jeffrey,
you're absolutely right in expecting this to work. I think the crucial thing for Hades is to find out which persistence provider you use. We need to know that internally to gain pagination metadata (in particular the total amount of entities without pagination applied). This is in general done by inspecting the EntityManager instance for its actual type.
So in your test case scenario everything seems to be fine. How do you create the EntityManager in your production environment. Does that differ from the way you do in test case scenario? We check for the actual implementation so there could be issues if the EntityManager is wrapped in a proxy itself.
Regards,
Ollie
PS: In case you can send me the project, feel free to hand me a zip of it.
RE: Hades with OpenJPA, Pageable queries work with Unit Test but not with Web App
-
Added by Jeffrey Cutler 6 months ago
Here's the emf entry in my applicationContext.xml
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="JPCutlerNewPU" />
<property name="jpaPropertyMap">
<map>
<entry key="openjpa.MaxFetchDepth" value="1"/>
<entry key="openjpa.Log" value="log4j" />
</map>
</property>
</bean>
I tried adding:
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter" />
</property>
and
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaDialect"/>
</property>
but both gave the original error message.
Regards,
Jeff
RE: Hades with OpenJPA, Pageable queries work with Unit Test but not with Web App
-
Added by Oliver Gierke 6 months ago
Hm, this looks like a plain vanilla setup. Sneeking through the relevant parts of the source I found some rough edges, that could cause the problem. I've opened #225 to file work on that topic agains. Feel free to watch this ticket and upcoming SNAPSHOT deployments.