第一行贴控制台报错信息:
execption.org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:174)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2274)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2270)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1739)
at objMethods.userSession.login(userSession.java:31)
at userActions.userLoginAction.login(userLoginAction.java:12)
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)
然后我们来讨论这个问题,报错问题显示在spring的xml文件配置中spring对hibernate。代码如下:
<bean id="propertyConfigure" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list><value>classpath:jdbc.properties</value></list>
</property>
</bean>
<bean id="mydbconnection" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="${hibernate.connection.driverClassName}"></property>
<property name="url" value="${hibernate.connection.url}"></property>
<property name="username" value="${hibernate.connection.username}"></property>
<property name="password" value="${hibernate.connection.password}"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" rel="mydbconnection"></property>
<property name="mappingLocations">
<list>
<value>classpath:adminObj/adminObj.hbm.xml</value>
<value>classpath:userModule/userObj.hbm.xml</value>
</list>
</property>
<property name="hibernateproperties" >
<props name="dialect" value="${hibernate.connection.dialect}"></props>
<props name="hibernate.show_sql" value="${hibernate.connection.show_sql}"></props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
spring的xml配置文件中,bean标签下sessionFactory的property:dataSource和hibernateproperties有报错,但是网上各种搜罗却是找不到有效的解决办法。