hibernate的异常 Configured SessionFactory: null
程序员文章站
2022-04-12 20:59:22
...
hibernate连接SQL Server 报错
12 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
15 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
18 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
22 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
70 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
70 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
143 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : com/ydc/domain/Employe.hbm.xml
201 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.ydc.domain.Employe -> Employe
217 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
270 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
270 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
270 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
385 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://localhost:1433;databasename=XHCommunityService
385 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}
814 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: Microsoft SQL Server, version: 10.50.1600
814 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: Microsoft SQL Server 2005 JDBC Driver, version: 2.0.1008.2
829 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.SQLServerDialect
835 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
837 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
837 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
837 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
837 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
837 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
838 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
838 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
838 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
838 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
838 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
838 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
839 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
839 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
840 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
840 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
840 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
840 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
840 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
840 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
842 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
843 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
843 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
843 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
843 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
874 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
984 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:572)
at com.ydc.view.TestMain.main(TestMain.java:18)
解决方法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- hibernate 设计者,给我们提供了一写常用的配置 -->
<!-- 配置使用的driver -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.username">sa</property>
<property name="connection.password">123456</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433;databasename=XHCommunityService</property>
<!-- 配置dialect方言,明确告诉hibernate连接是哪种数据库 -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- 显示出对应的sql语句-->
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<!-- 指定管理的对象映射文件 -->
<mapping resource="com/ydc/domain/Employe.hbm.xml"/>
</session-factory>
</hibernate-configuration>
在配置文件hibernate.cfg.xml中增加以下配置
<property name="current_session_context_class">thread</property>
上一篇: hibernate入门Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
推荐阅读
-
Oracle ORA-22908(NULL表值的参考)异常分析与解决方法
-
创建
sessionFactory错误, init方法调用失败;嵌套异常是org.hibernate.exception。 -
Oracle ORA-22908(NULL表值的参考)异常分析与解决方法
-
空指针异常,算得上是一个简单低级的错误吧 java.lang.NullPointerException: null
-
Hibernate中出现的异常
-
Oracle异常[ORA-22908:NULL表值的参考]问题的解析及解决方法
-
spring配置hibernate的sessionFactory的两种种方案
-
spring配置hibernate的sessionFactory的两种种方案
-
异常org.hibernate.QueryException: could not resolve property的原因
-
异常org.hibernate.QueryException: could not resolve property的原因