2005年12月2日
hibernate使用中常见的问题
classes根目录下放置了hibernate.properties及hibernate.cfg.xml文件。
classes\test目录下放置了Admin.hbm.xml文件。
工程中引用了hibernate3.jar、dom4j-1.5.2.jar及oracel数据库驱动程序classes12.jar、nls_charset12.jar、ocrs12.jar、hibernate3的lib下所有的包及其它要使用的包。
(1)hibernate警告 Could not obtain connection metadata
运行时报错如下:
2005-12-1 13:29:19 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:icts
2005-12-1 13:29:19 org.hibernate.connection.DriverManagerConnectionProvider configure
信息: connection properties: {user=system, password=****}
2005-12-1 13:29:19 org.hibernate.cfg.SettingsFactory buildSettings
警告: Could not obtain connection metadata
java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=150999297)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:335)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:361)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:442)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:321)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:118)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)
at test.Test.insertAdmin(Test.java:31)
at test.Test.myTest(Test.java:54)
at test.Test.main(Test.java:59)
2005-12-1 13:29:19 org.hibernate.cfg.SettingsFactory buildSettings
信息: JDBC batch size: 15
......
******
连接数据库有问题。检查用户名称与密码及数据库全局名称。
(2)报错:CUSTOMER is not mapped
错在这里:List list = session.createQuery("from CUSTOMER").list();
注意这里from后面对应的是类名,而不是数据库表名。
因为Customer类和表CUSTOMERS做了映射,在sql的检索中不是从数据库中取,而是从类中,这也是ORM的思想。
(3)报错:Could not bind factory to JNDI
此错误是配置文件的问题,如果hibernate配置文件有session_factory_name这个变量,<session-factory name="foo"> 会试图将一个SessionFactory实例以foo为名bind到jndi上,而有的application container不支持jndi绑定。把这个变量去掉即可。
posted @
2005-12-02 15:51 冷月畅晚 阅读(1514) |
评论 (0) |
编辑 收藏