无法使用Microsoft Access使用hibernate连接到数据库

时间:2015-04-15 03:43:09

标签: java hibernate ms-access-2007 hibernate-mapping

我遇到了这个例外:

1266 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
1266 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
1266 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - schema export unsuccessful
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
    at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
    at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
    at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:263)
    at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:219)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:370)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
    at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:11)
    at com.vaannila.student.Main.main(Main.java:14)
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.JDBCContext.connection(JDBCContext.java:160)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
    at com.vaannila.student.Main.main(Main.java:17)

请帮我解决这个问题。这是我的配置文件:

 <hibernate-configuration> 
 <session-factory> 
 <property name="hibernate.connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
 <property name="hibernate.connection.username"></property>
 <property name="connection.password"></property> 
 <property name="connection.pool_size">1</property>
 <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> 
 <property name="hibernate.conn.url">jdbc:odbc:demo</property> 

1 个答案:

答案 0 :(得分:0)

检查你的hibernate属性名称。

  

hibernate.conn.url

应该是:

  

hibernate.connection.url

你的

  

connection.passsword

应该是

  

hibernate.connection.password

其余看起来不错,但重新检查了文档。我看到你有一个空的密码字段和用户名属性。你的odbc连接是否需要名称和密码?

如果您缺少登录凭据等其他信息,修复连接字符串至少会给您一种新的错误。

这些xml配置非常挑剔!