我尝试通过Hibernate连接到Oracle。但我得到以下例外: javax.persistence.PersistenceException:
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:524)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:362)
com.sun.proxy.$Proxy239.getSingleResult(Unknown Source)
我使用以下配置:
map.put("hibernate.connection.username", "user");
map.put("hibernate.connection.password", "user");
map.put("hibernate.connection.url","jdbc:oracle:thin:@192.168.1.11:1521/rch");
map.put("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
map.put("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
map.put("hibernate.dialect","org.hibernate.dialect.Oracle10gDialect");
map.put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");
map.put("hibernate.c3p0.max_size", "100");
map.put("hibernate.c3p0.min_size", "1");
map.put("hibernate.c3p0.acquire_increment", "1");
map.put("hibernate.c3p0.idle_test_period", "300");
map.put("hibernate.c3p0.max_statements", "0");
map.put("hibernate.c3p0.timeout", "3600");
map.put("hibernate.c3p0.checkoutTimeout", "60000");
map.put("hibernate.show_sql","true");
每次调用singleResult方法时,我都会遇到此异常。使用相同JDBC驱动程序但不使用hibernate的程序可以轻松连接相同的数据(URL和凭证)。