I have an extremely simple web application running in Tomcat using Spring 3.0.2, Hibernate 3.5.1, JPA 2, and Derby. I am defining all of my database connectivity in persistence.xml and merely using Spring for dependency injection. I am using embedded Derby as my database.
Everything works correctly when I define the driver and url properties in persistence.xml in the classic Hibernate manner as thus:
<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="hibernate.connection.url" value="jdbc:derby:webdb;create=true"/>
The problems occur when I switch my configuration to the JPA2 standardized properties as thus:
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:webdb;create=true"/>
When using the JPA2 property keys, the application bails hard with the following exception:
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
Does anyone know why this is failing?
NOTE: I have copied the javax… property strings straight from the Hibernate reference documentation, so a typo is extremely unlikely.
The answer appears to be that this is a Spring issue, likely stemming from the use of the
LocalContainerEntityManagerFactoryBean. I was using Spring to enable the use of the@PersistenceContextannotation rather than manually initializing the EntityManager in the standard Java SE way. When I replaced the use@PersistenceContextwithPersistence.createEntityManagerFactory("WebApp").createEntityManager();(and commented the EntityManager stuff out of my Spring config), everything worked as expected.For reference, this was the Spring configuration I was using: