问题描述
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection avalableat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1403)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3637)at org.apache.catalina.core.StandardContext.start(StandardContext.java:4073)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:909)at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:872)at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1106)at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1019)at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1011)at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:440)at org.apache.catalina.core.StandardService.start(StandardService.java:450)at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)at org.apache.catalina.startup.Catalina.start(Catalina.java:537)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)Caused by: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection avalableat 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 org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855)at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774)at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)... 36 more我的hibernate.cfg.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"><!-- Generated by MyEclipse Hibernate Tools. --><hibernate-configuration><session-factory><property name="connection.url">jdbc:oracle:thin:@192.168.2.250:1521:COMMERCE</property><property name="connection.username">SUPERSYS</property><property name="connection.password">role1</property><property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property><property name="myeclipse.connection.profile">oracle</property><property name="show_sql">true</property><property name="dialect">org.hibernate.dialect.Oracle9Dialect</property><mapping resource="com/xl/dao/FinanceBankBusiness.hbm.xml" /></session-factory></hibernate-configuration>请求各位帮我看看把
解决方案
看看提示信息org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection avalable 也很明确,要你在Connection 连接之前设置好hibernate.dialect,而你用的是dialect,程序没有识别,把dialect改为hibernate.dialect就好了。
解决方案二:
飞雪回答的问题真多啊
解决方案三:
高手就是不一样,仰慕啊
解决方案四:
# <property name="dialect"> # org.hibernate.dialect.Oracle9Dialect # </property> 把那么值改为hibernate.dialect