Using Hibernate 3.2cr2, entity manager 3.2cr1, and annotations 3.2cr1
The problem (which is, I emphasize, probably not in any Hibernate code, but I'm looking for help tracking it down):
if I instantiate an EntityManagerFactory manually, via Persistence.createEntityManagerFactory("myPersistenceContext"), the EMF is created and I have useful EntityManagers I can use to work directly with JPA. I'm providing the connection details in the persistence.xml, like so:
Code:
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="database.connection.url" value="jdbc:hsqldb:mem:kb"/>
<property name="database.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="database.connection.password" value=""/>
<property name="database.connection.username" value="sa"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
(note that create-drop is set, so on startup, it will run SchemaExport; that's desirable because I'm trying to run some tests) If I instantiate an EntityManagerFactory with Spring 2.0M4 and its JPA support (org.springframework.orm.jpa.LocalEntityManagerFactoryBean), using the same persistence.xml that works above*, I get UnsupportedOperationExceptions when Spring uses JpaTemplate because in this environment, the UserSuppliedConnectionProvider appears to be in use:
Code:
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:178)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:131)
at org.hibernate.impl.SessionFactoryImpl.&init&(SessionFactoryImpl.java:308)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createEntityManagerFactory(LocalEntityManagerFactoryBean.java:102)
This happens whether I inject an EntityManagerFactory or a JpaTemplate into the JpaDaoSupport-extending class. I'm pretty sure it's not a classloading issue, either, because I've tried adding the "manual" Persistence.createEntityManagerFactory calls to the classes under test, and they sail through without issue.
* verified this far: if I make persistence.xml not well-formed, my unit tests throws the expected SAX exceptions at startup.
I'm pretty sure it's something in the Spring environment that accounts for the difference; for one, Spring's LocalEntityManagerFactoryBean makes the same unexceptionable calls to Persistence.createEntityManagerFactory my code makes. Specifically, I'm looking for guidance about
what could cause Hibernate to use the UserSuppliedConnectionProvider when the connection details are (apparently) available to it?
Of course, if anybody has run into the same problem and has a specific fix for this, I wouldn't turn my nose up at that either =)