hibernate---java.lang.UnsupportedOperationException: The user must supply a JDBC connection

    在配置hibernate时,执行代码时一直抛错:

Exception in thread "main" java.lang.UnsupportedOperationException: The user must supply a JDBC connection
	at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
	at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
	at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
	at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1616)
	at org.hibernate.loader.Loader.doQuery(Loader.java:717)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
	at org.hibernate.loader.Loader.loadEntity(Loader.java:1953)
	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
	at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3270)
	at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
	at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
	at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
	at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1080)
	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:997)
	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:990)
	at com.ado.test.hibernate.HibernateTest.main(HibernateTest.java:25)

    后来看了后台的源码,发现创建的ConnectionProvider实例为UserSuppliedConnectionProvider(用户自定义的Provider),配置有点异常。断点跟踪了创建该实例的代码,原来是因为在根据各个配置属性创建该实例时,因为配置属性关键字与hibernate关键字不一样,所以导致创建了用户自定义的Provider,从而出现了上面的异常。

    测试代码使用的是hibernate 3.5.6,标准的关键字可以查看org.hibernate.cfg.Environment类中的定义。hibernate版本不一样,使用的关键字也不一样。这点需要注意。

    hibernate 3.5.6使用的是:

hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
hibernate.connection.password




你可能感兴趣的:(Hibernate)