`
JazGung
  • 浏览: 31414 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connec

阅读更多

今天在写Hibernate代码的时候遇到如下报错:

 

org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection avalable
	at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:107)
	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:138)
	at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
	at net.jazgung.po.PoTester.beforeClass(PoTester.java:19)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

java.lang.NullPointerException
	at net.jazgung.po.PoTester.afterClass(PoTester.java:24)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 

 在google上找了很久也没能找到解决方法,后发现有如下的代码错误:

 

new Configuration().buildSessionFactory()

 改为

 

new Configuration().configure().buildSessionFactory()
 后,问题解决。
1
0
分享到:
评论

相关推荐

    org.hibernate.HibernateException: No Hibernate Session bound to thread

    然而,在使用 Hibernate 进行数据库操作时,经常会遇到 "No Hibernate Session bound to thread" 的错误信息。本文将详细介绍该错误的解决方案。 错误原因 "No Hibernate Session bound to thread" 错误信息通常是...

    解决SpringDataJPA报错:org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null w

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/...

    HIbernate4.3.6整合c3p0所需jar

    Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.connection.C3P0ConnectionProvider] at org.hibernate.engine.jdbc.connections.internal....

    com.microsoft.sqlserver.jdbc.SQLServerException: 只进结果集不支持请求的操作 解决方案

    query.setHint("org.hibernate.fetchSize", 20); // 设置查询结果集大小 query.setFetchSize(20); List<Game> games = query.list(); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx....

    Spring4.0+Hibernate4.0+Struts2.3整合案例

    2、报错:org.hibernate.HibernateException: No Session found for current thread 意思是必须在transcation.isActive()条件下才能执行, 可以解决办法是:当方法不需要事务支持的时候,使用 Session ...

    jdbc+hibernate的jar包

    3. `org.hibernate.HibernateException`:Hibernate抛出的异常类。 4. `org.hibernate.Query`和`org.hibernate Criteria`:用于执行HQL(Hibernate Query Language)和Criteria API查询,比直接使用SQL更加灵活。 ...

    Hibernate配置常见错误

    错误表现:在初始化SessionFactory时,可能出现“org.hibernate.HibernateException: Could not instantiate dialect class”等异常,这通常是因为Hibernate配置文件中的dialect设置不正确或对应的JDBC驱动未引入。...

    Hibernate+Proxool配置

    由于项目需求的需要,我们引入了连接池。...我们采用了Hibernate,所以可以考虑hibernate自带的连接池机制,但是发现效率不高,而且Hibernate也推荐使用c3p0或Proxool连接池,在我们的项目中采用了Proxool

    Generating Artifacts问题解决.doc

    "GeneratingArtifacts" org.hibernate.HibernateException: ProxoolProvider unable to load JAXP configurator file: proxool_mysql.xml ``` **解析:** 这个错误提示表明,在使用Proxool作为连接池提供者时,...

    Delphi 中的Hibernate

    8. **异常处理**:Hibernate抛出的异常通常继承自`org.hibernate.HibernateException`。在Delphi中,你需要适配这些异常到Delphi的异常处理机制。 9. **性能优化**:了解并应用最佳实践,如延迟加载、批处理更新和...

    Jbuilder里配置Hibernate

    <property name="dialect">org.hibernate.dialect.MySQL5Dialect <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread <!-- Echo all ...

    spring_MVC源码

    05.dataSource.dialect=org.hibernate.dialect.MySQL5Dialect 06.dataSource.serverName=localhost:3306 07.dataSource.url=jdbc:mysql://localhost:3306/test 08.dataSource.properties=user=${dataSource....

    Struts2 + Hibernate 分页程序实例

    import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.cfg.Configuration; /** * Configures and provides access to Hibernate sessions, tied to the * current ...

    hibernate测试时遇到的几个异常及解决方法汇总

    2. java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector ...

    hibernate配置properties

    jdbcPros.setProperty("hibernate.connection.driver_class", "org.gjt.mm.mysql.Driver"); jdbcPros.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/your_db"); jdbcPros.setProperty(...

    J2EE利用Hibernate采用B/S架构网页设计

    import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.cfg.Configuration; /** * Configures and provides access to Hibernate sessions, tied to the * current ...

    spring配置jbpm

    --(JBPMConfig)avoid happen: org.hibernate.HibernateException: Could not instantiate cache implementation --> <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider ...

Global site tag (gtag.js) - Google Analytics