Xerces Strikes Again
I’m working on a Java project currently. We’re using Maven2, Spring 2.0 and JPA using Hibernate. One of the last things I wanted to install was connection pooling. It should have been an easy installation because all I needed to do was add c3p0 as my data source and inject it into my entity manager factory. My configuration looked like this:
When I ran a test in maven I noticed that c3p0 was setting up and I could see debug messages from it but then it failed. Looking at the surefire report I saw:
Error creating bean with name ‘entityManagerFactory’ defined in URL [file:/Users/mark/projects/quadran/target/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.StackOverflowError
Caused by: java.lang.StackOverflowError
at java.lang.String.toLowerCase(String.java:2213)
at java.lang.String.toLowerCase(String.java:2277)
at org.apache.xerces.util.URI.setScheme(URI.java:908)
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.(URI.java:211)
at org.apache.xerces.util.URI.(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 org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(XMLSchemaLoader.java:588)
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 org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(XMLSchemaLoader.java:588)
and it continues on and on like that. It took me quite some time to figure this one out and the error had nothing to do with anything specific to my project and so it was hard to track down. I also couldn’t find any others online with the same error except one. So I decided to write about it on my blog to help others if they happen to have the same error. Here’s the forum page that helped me:
http://forum.springframework.org/showthread.php?t=34654
The solution? Xerces 2.0.2 has some bug and maven2 comes with it. Instead you need to use Xerces 2.8.1.
And that solved the issue, c3p0 was able to connect, all my tests passes.