Back Forum Reply New
Hello

I'm trying to get Spring JPA support working in a junit test. Please note that everything worked until I've migrated persistence.xml and my spring-config.xml to the current state.

This is the error I'm receiving:Code:
-------------------------------------------------------T E S T S
-------------------------------------------------------
Running com.test.minisearch.server.ItemServiceImplBenchmarkTest
Warning: Caught exception attempting to use SAX to load a SAX XMLReader
Warning: Exception was: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
Warning: I will print the stack trace then carry on using the default SAX parser
java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:199)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150)
at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
at org.dom4j.io.SAXReader.setFeature(SAXReader.java:218)
at org.hibernate.ejb.Ejb3Configuration.addXMLEntities(Ejb3Configuration.java:438)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:360)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
at org..orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:218)
at org..orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
at org..beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
at org..beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at org..beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
at org..beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org..beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:284)
at org..context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org..context.support.ClassPathXmlApplicationContext.lt;initgt;(ClassPathXmlApplicationContext.java:91)
at org..context.support.ClassPathXmlApplicationContext.lt;initgt;(ClassPathXmlApplicationContext.java:75)
at org..context.support.ClassPathXmlApplicationContext.lt;initgt;(ClassPathXmlApplicationContext.java:65)
at com.test.minisearch.server.ItemServiceImpl.lt;clinitgt;(ItemServiceImpl.java:30)
at com.test.minisearch.server.ItemServiceImplBenchmarkTest.testBenchmarkSearch_JPA(ItemServiceImplBenchmarkTest.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.219 sec lt;lt;lt; FAILURE!
Running com.test.minisearch.server.ItemServiceImplTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec lt;lt;lt; FAILURE!
This is my persistence.xml:Code:
lt;persistence xmlns=quot;xml/ns/persistencequot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xsi:schemaLocation=quot;xml/ns/persistence       xml/ns/persistence/persistence_1_0.xsdquot;
version=quot;1.0quot;gt;
lt;persistence-unit name=quot;pu1quot; transaction-type=quot;RESOURCE_LOCALquot;gt;
lt;!-- All persistence classes must be listed --gt;
lt;classgt;com.test.minisearch.server.model.Itemlt;/classgt;
lt;classgt;com.test.minisearch.server.model.ItemNamelt;/classgt;
lt;/persistence-unitgt;
lt;/persistencegt;
spring-config.xml:Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;dtd/spring-beans.dtdquot;gt;

lt;beansgt;
lt;bean id=quot;dataSource1quot;
class=quot;com.mchange.v2.c3p0.ComboPooledDataSourcequot;gt;
lt;property name=quot;driverClassquot; value=quot;com.mysql.jdbc.Driverquot; /gt;
lt;property name=quot;jdbcuclquot;
value=quot;jdbc:mysql--eclipse.lan.hell:3306/testquot; /gt;
lt;property name=quot;userquot; value=quot;testquot; /gt;
lt;property name=quot;passwordquot; value=quot;***quot; /gt;
lt;/beangt;

lt;bean id=quot;entityManagerFactoryquot;
class=quot;org..orm.jpa.LocalContainerEntityManagerFactoryBeanquot;gt;
lt;property name=quot;dataSourcequot; ref=quot;dataSource1quot; /gt;
lt;property name=quot;jpaVendorAdapterquot;gt;
lt;bean
class=quot;org..orm.jpa.vendor.HibernateJpaVendorAdapterquot;gt;
lt;property name=quot;databasePlatformquot; value=quot;org.hibernate.dialect.MySQLInnoDBDialectquot;/gt;
lt;property name=quot;databasequot; value=quot;HSQLquot; /gt;
lt;property name=quot;showSqlquot; value=quot;truequot; /gt;
lt;property name=quot;generateDdlquot; value=quot;truequot; /gt;
lt;/beangt;
lt;/propertygt;
lt;property name=quot;loadTimeWeaverquot;gt;
lt;bean
class=quot;org..instrument.classloading.SimpleLoadTimeWeaverquot; /gt;
lt;/propertygt;
lt;/beangt;
lt;/beansgt;
My applicationcontext is instanciated using a static member variable in one of my services since the application is not running inside a J2EE container (is there a better way to solve this?)Code:
protected static ApplicationContext ctx = new ClassPathXmlApplicationContext(quot;spring-config.xmlquot;);Turns out that you should *not* specify a load time weaver when using the hibernate JPA provider.
¥
Back Forum Reply New