I have a working test for a Hibernate JPA based DAO running with LocalEntityManagerFactoryBean. The test is a JUnit test based on AbstractTransactionalDataSourceSpringContextTests.
As soon as I switch to the LocalContainerEntityManagerFactoryBean in order to explicitly set the dataSource the code starts a recursion and ends with a StackOverflowError!Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property name="url" value="jdbc:hsqldb:mem:database" /> <property name="username" value="sa" /> <property name="password" value="" /> <property name="defaultAutoCommit" value="false"></property> </bean> <!--bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="freelancer" /> </bean--> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="persistenceUnitName" value="freelancer" /> </bean> <bean id="abstractDao" abstract="true"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean id="projectDao" parent="abstractDao" class="at.martinahrer.freelancer.dao.jpa.JpaProjectDao"> <property name="implementationClass" value="at.martinahrer.freelancer.model.Project" /> </bean> <bean id="activityDao" parent="abstractDao" class="at.martinahrer.freelancer.dao.jpa.JpaActivityDao"> <property name="implementationClass" value="at.martinahrer.freelancer.model.Activity" /> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> </beans>
Is there any parameter missing that configures the LocalContainerEntityManagerFactoryBean - I only aim at overriding the dataSource as specified in persistence.xml!
Code:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext-jpa.xml]: Invocation of init method failed; nested exception is java.lang.StackOverflowError Caused by: java.lang.StackOverflowError at org.apache.xerces.util.URI.isConformantSchemeName(URI.java:1213) at org.apache.xerces.util.URI.setScheme(URI.java:904) at org.apache.xerces.util.URI.initializeScheme(URI.java:576) at org.apache.xerces.util.URI.initialize(URI.java:400) at org.apache.xerces.util.URI.<init>(URI.java:211) at org.apache.xerces.util.URI.<init>(URI.java:195) at org.apache.xerces.impl.XMLEntityManager.expandSystemId(XMLEntityManager.java:1140) at org.apache.xerces.impl.XMLEntityManager.resolveEntity(XMLEntityManager.java:581) at org.apache.xerces.impl.xs.XMLSchemaLoader.xsdToXMLInputSource(XMLSchemaLoader.java:625) at org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(XMLSchemaLoader.java:580) at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:489) at org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(XMLSchemaLoader.java:588) at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:489) at ....


Reply With Quote