CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  框架、开源

hibernate3 + mysql5.0的问题

楼主firewangcool(fire)2006-06-03 17:58:19 在 Java / 框架、开源 提问

兄弟这两天刚刚开始学习hibernate,从网上下载了最新的hibernate3,数据库使用mysql5.0;我对hibernate和mysql都不是很熟。  
  出现了问题:  
  信息:   schema   export   complete  
  Exception   in   thread   "main"   org.hibernate.HibernateException:   No   CurrentSessionContext   configured!  
  at   org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:506)  
  at   events.EventManager.CreateAndStoreEvent(EventManager.java:45)  
  at   events.EventManager.main(EventManager.java:37)  
  程序执行时的输出和xml文档的配置内容已经贴了出来,请各位大侠过目瞅瞅是什么原因?  
  程序执行输出:  
  2006-6-3   17:46:04   org.hibernate.cfg.Environment   <clinit>  
  信息:   Hibernate   3.1.3  
  2006-6-3   17:46:04   org.hibernate.cfg.Environment   <clinit>  
  信息:   hibernate.properties   not   found  
  2006-6-3   17:46:04   org.hibernate.cfg.Environment   <clinit>  
  信息:   using   CGLIB   reflection   optimizer  
  2006-6-3   17:46:04   org.hibernate.cfg.Environment   <clinit>  
  信息:   using   JDK   1.4   java.sql.Timestamp   handling  
  2006-6-3   17:46:04   org.hibernate.cfg.Configuration   configure  
  信息:   configuring   from   resource:   /hibernate.cfg.xml  
  2006-6-3   17:46:04   org.hibernate.cfg.Configuration   getConfigurationInputStream  
  信息:   Configuration   resource:   /hibernate.cfg.xml  
  2006-6-3   17:46:04   org.hibernate.cfg.Configuration   addResource  
  信息:   Reading   mappings   from   resource:   events/Event.hbm.xml  
  2006-6-3   17:46:05   org.hibernate.cfg.HbmBinder   bindRootPersistentClassCommonValues  
  信息:   Mapping   class:   events.Event   ->   EVENTS  
  2006-6-3   17:46:05   org.hibernate.cfg.Configuration   doConfigure  
  信息:   Configured   SessionFactory:   null  
  2006-6-3   17:46:05   org.hibernate.connection.DriverManagerConnectionProvider   configure  
  信息:   Using   Hibernate   built-in   connection   pool   (not   for   production   use!)  
  2006-6-3   17:46:05   org.hibernate.connection.DriverManagerConnectionProvider   configure  
  信息:   Hibernate   connection   pool   size:   1  
  2006-6-3   17:46:05   org.hibernate.connection.DriverManagerConnectionProvider   configure  
  信息:   autocommit   mode:   false  
  2006-6-3   17:46:05   org.hibernate.connection.DriverManagerConnectionProvider   configure  
  信息:   using   driver:   com.mysql.jdbc.Driver   at   URL:   jdbc:mysql://localhost:3306/testmysql  
  2006-6-3   17:46:05   org.hibernate.connection.DriverManagerConnectionProvider   configure  
  信息:   connection   properties:   {user=root,   password=****}  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   RDBMS:   MySQL,   version:   5.0.22-community-nt  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   JDBC   driver:   MySQL-AB   JDBC   Driver,   version:   mysql-connector-java-5.0.0-beta   (   $Date:   2005-11-17   16:14:47   +0100   (Thu,   17   Nov   2005)   $,   $Revision$   )  
  2006-6-3   17:46:05   org.hibernate.dialect.Dialect   <init>  
  信息:   Using   dialect:   org.hibernate.dialect.HSQLDialect  
  2006-6-3   17:46:05   org.hibernate.transaction.TransactionFactoryFactory   buildTransactionFactory  
  信息:   Using   default   transaction   strategy   (direct   JDBC   transactions)  
  2006-6-3   17:46:05   org.hibernate.transaction.TransactionManagerLookupFactory   getTransactionManagerLookup  
  信息:   No   TransactionManagerLookup   configured   (in   JTA   environment,   use   of   read-write   or   transactional   second-level   cache   is   not   recommended)  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Automatic   flush   during   beforeCompletion():   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Automatic   session   close   at   end   of   transaction:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   JDBC   batch   size:   15  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   JDBC   batch   updates   for   versioned   data:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Scrollable   result   sets:   enabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   JDBC3   getGeneratedKeys():   enabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Connection   release   mode:   auto  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Default   batch   fetch   size:   1  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Generate   SQL   with   comments:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Order   SQL   updates   by   primary   key:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   createQueryTranslatorFactory  
  信息:   Query   translator:   org.hibernate.hql.ast.ASTQueryTranslatorFactory  
  2006-6-3   17:46:05   org.hibernate.hql.ast.ASTQueryTranslatorFactory   <init>  
  信息:   Using   ASTQueryTranslatorFactory  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Query   language   substitutions:   {}  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Second-level   cache:   enabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Query   cache:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   createCacheProvider  
  信息:   Cache   provider:   org.hibernate.cache.NoCacheProvider  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Optimize   cache   for   minimal   puts:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Structured   second-level   cache   entries:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Echoing   all   SQL   to   stdout  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Statistics:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Deleted   entity   synthetic   identifier   rollback:   disabled  
  2006-6-3   17:46:05   org.hibernate.cfg.SettingsFactory   buildSettings  
  信息:   Default   entity-mode:   pojo  
  2006-6-3   17:46:05   org.hibernate.impl.SessionFactoryImpl   <init>  
  信息:   building   session   factory  
  2006-6-3   17:46:05   org.hibernate.impl.SessionFactoryObjectFactory   addInstance  
  信息:   Not   binding   factory   to   JNDI,   no   JNDI   name   configured  
  2006-6-3   17:46:05   org.hibernate.tool.hbm2ddl.SchemaExport   execute  
  信息:   Running   hbm2ddl   schema   export  
  2006-6-3   17:46:05   org.hibernate.tool.hbm2ddl.SchemaExport   execute  
  信息:   exporting   generated   schema   to   database  
  2006-6-3   17:46:05   org.hibernate.tool.hbm2ddl.SchemaExport   execute  
  信息:   schema   export   complete  
  Exception   in   thread   "main"   org.hibernate.HibernateException:   No   CurrentSessionContext   configured!  
  at   org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:506)  
  at   events.EventManager.CreateAndStoreEvent(EventManager.java:45)  
  at   events.EventManager.main(EventManager.java:37)  
   
  hibernate.hbm.xml配置文件的内容如下:  
  <?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>  
  <!--   database   connection   setting   -->  
  <property   name="connection.driver_class">  
  com.mysql.jdbc.Driver  
  </property>  
  <property   name="connection.url">  
  jdbc:mysql://localhost:3306/testmysql  
  </property>  
  <property   name="connection.username">root</property>  
  <property   name="connection.password">password</property>  
   
  <!--   jdbc   connection   pool   -->  
  <property   name="connection.pool_size">1</property>  
   
  <!--   SQL   dialect   -->  
  <property   name="dialect">  
  org.hibernate.dialect.HSQLDialect  
  </property>  
   
  <!--   enable   hibernate's   automatic   session   context   managerment       -->  
  <property   name="currect_session_context_class">thread</property>  
   
  <!--   Disable   the   second-level   cache   -->  
  <property   name="cache.provider_class">  
  org.hibernate.cache.NoCacheProvider  
  </property>  
  <!--   Echo   all   executed   SQL   to   stdout   -->  
  <property   name="show_sql">true</property>  
  <!--   Drop   and   re-create   the   database   schema   on   startup   -->  
  <property   name="hbm2ddl.auto">create</property>  
   
  <mapping   resource="events/Event.hbm.xml"   />  
   
  </session-factory>  
  </hibernate-configuration>  
  问题点数:100、回复次数:4Top

1 楼im9527(听说现在做和尚比泡妞还难---九五二七)回复于 2006-06-03 22:58:26 得分 50

如果你是用hibernate.cfg.xml的话  
  生成session的方法应该是用以下这种文件  
  public   static   SessionFactory   sessionFactory;  
  private   static   Configuration   configuration;  
  static   {  
   
  try   {  
  configuration   =   new   Configuration();  
   
  sessionFactory   =   configuration.configure().buildSessionFactory();  
  }   catch   (Throwable   ex)   {  
   
  throw   new   ExceptionInInitializerError(ex);  
  }  
  }Top

2 楼firewangcool(fire)回复于 2006-06-03 23:57:59 得分 0

sessionFactory   =   new   Configuration().configure().buildSessionFactory();  
  Session   session   =   sessionFactory.getCurrentSession();  
  我就是用的这种方法啊!  
  不知道是不是我配置什么地方不对啊!Top

3 楼realdreamer(楼主英明,贫僧久仰大名,特来拜见)回复于 2006-06-04 00:33:44 得分 50

getCurrentSession   不对  
  用openSession    
   
  你再看下   hibernate   api   doc   对   openSession   和   getCurrentSession   的说明Top

4 楼firewangcool(fire)回复于 2006-06-04 10:50:57 得分 0

谢谢各位仁兄,我改成了openSession就成功了,但是不知道为什么我昨天晚上也改成openSession就没有成功!呵呵!  
  能解释一下openSession和getCurrentSession()的不同吗?  
  我是根据Hibernate   Reference   Documentation里面的例子写的程序。Top

相关问题

关键词

得分解答快速导航

  • 帖主:firewangcool
  • im9527
  • realdreamer

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo