Hibernate: javax.persistence.* driver properties cause UnsupportedOperationException: The user must supply a JDBC connection?
I'm using
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/whatever" />
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" />
in all of my JavaSE test apps with Hibernate without problems. However, when using the same in a webapp (Tomcat) an exception is thrown:
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
org.hibernate.loader.Loader.prepareQueryStatemen开发者_C百科t(Loader.java:1596)
org.hibernate.loader.Loader.doQuery(Loader.java:717)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
org.hibernate.loader.Loader.loadEntity(Loader.java:1933)
org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3270)
org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1080)
org.hibernate.impl.SessionImpl.get(SessionImpl.java:997)
org.hibernate.impl.SessionImpl.get(SessionImpl.java:990)
org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:182)
com.kawoolutions.bbstats.servlet.BasketballStatsServlet.doGet(BasketballStatsServlet.java:405)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
I couldn't find anything useful on the net, so I grabbed a backup and noticed the only change I made was that I previously used:
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/whatever" />
<property name="hibernate.connection.username" value="" />
<property name="hibernate.connection.password" value="" />
After reverting to the hibernate.* properties the exception went away!
What's wrong here? Why do the javax.persistence.* properties work in a JavaSE environment but not in my webapp? It's really strange...
javax.persistence.*
properties were introduced in JPA 2.0, that is in Hibernate 3.5 and above. If you use previous version of Hibernate, they don't work.
精彩评论