如果我沒有以編程方式設置任何東西,只是調用Configuration configuration = new Configuration().configure();
並使用hibernate.properties(如下所示),一切都很好。只要我嘗試以編程方式提供用戶名,密碼和連接URL,我就會得到一個奇怪的異常,暗示着hbm文件。我錯過了什麼?UnsupportedOperationException:應用程序必須提供JDBC連接
這個作品
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://myEC2/mCruiseOnServerDB?autoReconnect=true&failOverReadOnly=false&maxReconnects=10
hsqldb.write_delay_millis=0
shutdown=true
hibernate.connection.username=root
hibernate.connection.password=mypwd
hibernate.connection.pool_size=2
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.c3p0.idle_test_period=300
hibernate.c3p0.timeout=120
按照@Kshitij建議。做混合模式。
的hibernate.properties現在
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hsqldb.write_delay_millis=0
shutdown=true
hibernate.connection.pool_size=2
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
守則
String connection = "jdbc:mysql://"
+ Globals.DBSERVER
+ "/mCruiseOnServerDB?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
Configuration configuration = new Configuration()
.setProperty("hibernate.connection.url", connection)
.setProperty("hibernate.connection.username", Globals.DB_USER_NAME)
.setProperty("hibernate.connection.password", Globals.DB_PASSWORD);
configuration.configure();
sessionFactory = configuration
.buildSessionFactory(new ServiceRegistryBuilder()
.buildServiceRegistry());
例外
現在我得到這個例外,一個是在每一個mapping resource
進入我的hbm文件。
11 May 2013 08:46:31,969 1300 [main] FATAL ReadOnlyOperations - Have chosen to ignore this runtime exception java.lang.UnsupportedOperationException: The application must supply JDBC connections, may be fatal, examine this carefully
11 May 2013 08:46:31,969 1300 [main] FATAL ReadOnlyOperations - java.lang.UnsupportedOperationException: The application must supply JDBC connections
摘要
如果我使用所有hibernate.properties
沒有代碼(在代碼中沒有.setProperty)一切都很正常。如果我使用部分hibernate.properties
和部分代碼(服務器,用戶名,密碼),我會在每個映射屬性的hbm中收到錯誤。
我需要有人幫助我找出我失蹤的東西。它應該是非常基本的東西。
[請參見參考資料:http://stackoverflow.com/questions/11211451/connection-cannot-be-null-when-hibernate-dialect-not -set) – gks 2013-05-10 11:23:56
我已經試過了,不起作用。 – Siddharth 2013-05-10 11:27:56