【发布时间】:2013-05-05 01:19:08
【问题描述】:
如果我没有以编程方式设置任何内容,只需调用 Configuration configuration = new Configuration().configure(); 并使用 hibernate.properties(如下所示),一切都会很好。一旦我尝试以编程方式提供用户名、密码和连接 url,我就会得到一个奇怪的异常,提示 hbm 文件。我错过了什么?
这个工程
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());
例外
我现在得到了这个异常,我的 hbm 文件中的每个 mapping resource 条目都有一个。
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 中得到错误。
我需要有人帮我弄清楚我缺少什么。它应该是非常基本的东西。
【问题讨论】:
-
我已经试过了,还是不行。
标签: hibernate hibernate-mapping