问题描述
请问各位: 我在使用junit进行单元测试的时候,到实例化SessionFactory的时候不成功,控制台打印的信息如下:2013-8-14 15:36:45 org.hibernate.annotations.common.Version <clinit>INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}2013-8-14 15:36:45 org.hibernate.Version logVersionINFO: HHH000412: Hibernate Core {4.1.9.Final}2013-8-14 15:36:45 org.hibernate.cfg.Environment <clinit>INFO: HHH000206: hibernate.properties not found2013-8-14 15:36:45 org.hibernate.cfg.Environment buildBytecodeProviderINFO: HHH000021: Bytecode provider name : javassist2013-8-14 15:36:45 org.hibernate.cfg.Configuration configureINFO: HHH000043: Configuring from resource: /hibernate.cfg.xml2013-8-14 15:36:45 org.hibernate.cfg.Configuration getConfigurationInputStreamINFO: HHH000040: Configuration resource: /hibernate.cfg.xml2013-8-14 15:36:45 org.hibernate.cfg.Configuration addResourceINFO: HHH000221: Reading mappings from resource: com/hanqi/po/TempPrice.hbm.xml2013-8-14 15:36:45 org.hibernate.cfg.Configuration addResourceINFO: HHH000221: Reading mappings from resource: com/hanqi/po/Product.hbm.xml2013-8-14 15:36:45 org.hibernate.cfg.Configuration addResourceINFO: HHH000221: Reading mappings from resource: com/hanqi/po/CurrentPrice.hbm.xml2013-8-14 15:36:45 org.hibernate.cfg.Configuration addResourceINFO: HHH000221: Reading mappings from resource: com/hanqi/po/LookupCode.hbm.xml2013-8-14 15:36:45 org.hibernate.cfg.Configuration addResourceINFO: HHH000221: Reading mappings from resource: com/hanqi/po/LookupType.hbm.xml2013-8-14 15:36:45 org.hibernate.cfg.Configuration doConfigureINFO: HHH000041: Configured SessionFactory: null我检查过我的hibernate.cfg.xml文件和未发现错误。如下:<hibernate-configuration><session-factory> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> <property name="connection.username">POSMAN</property> <property name="connection.password">POSMAN</property> <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property><mapping resource="com/hanqi/po/TempPrice.hbm.xml"/><mapping resource="com/hanqi/po/Product.hbm.xml"/><mapping resource="com/hanqi/po/CurrentPrice.hbm.xml"/><mapping resource="com/hanqi/po/LookupCode.hbm.xml"/><mapping resource="com/hanqi/po/LookupType.hbm.xml"/></session-factory></hibernate-configuration>xxx.hbm.xml文件我也检查过未发现问题,请问会是在哪个地方出的错。感谢!
解决方案
1 代码没问题的话,请把所有的映射文件删除,看下是什么效果2 把配置属性修改成 <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate. connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> <property name="hibernate.connection.username">POSMAN</property> <property name="hibernate.connection.password">POSMAN</property>官方文档时这种写法http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/session-configuration.html
解决方案二:
你的错误信息:INFO: HHH000206: hibernate.properties not found 需要的属性文件没找到,那么很可能你的jar包没放对位置也可能hibernate.cfg.xml 路径问题吧!仔细检查!
解决方案三:
只有这些报错信息吗?