2017-01-17 3 views
0

Ich weiß, das ist eine häufig gestellte Frage, aber keine der verfügbaren Lösungen funktionieren für mich. Unten ist mein booltstraps.xml:org.hibernate.HibernateException: Zugriff auf DialectResolutionInfo kann nicht null sein, wenn 'Hibernate.dialect'

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 


<!-- 
    This configuration file configures the Database Access Object or DAO objects. 
    It is used at system start to bootstrap configurations. 
    DAO objects will also be used by the main PassMark application. 
--> 
    <bean class="com.passmarksecurity.utils.AppContext" id="appContext"> 
     <description>Simple bean to handle initializations</description> 
    </bean> 

    <bean class="com.company.csd.dao.transaction.CompanyHibernateTransactionManager" id="transactionManager"> 
     <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 

    <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource"> 
     <description> 
      Database configuration settings. 
     <!-- config--> 
     <property name="driverClassName"> 
      <value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value> 
     </property> 
     <property name="url"> 
      <value>jdbc:sqlserver://localhost:1433;databaseName=CORE</value> 
     </property> 
     <property name="username"> 
      <value>core_user</value> 
     </property>  
     <property name="password"> 
      <value>core_user</value> 
     </property> 
     <!-- config-->  
    </bean> 


    <!-- Configure DAOFactory --> 
    <bean class="com.passmarksecurity.dao.api.DAOFactory" id="daoFactory" init-method="configPostProcess"> 
     <property name="DAOConfig"> 
      <ref bean="daoConfig"/> 
     </property> 
    </bean> 
    <!-- IMPORTANT: Configure this setting first --> 

    <!-- This is for Oracle configuration with database images --> 
    <bean class="com.passmarksecurity.dao.config.DAOConfigMSSQL" id="daoConfig"/> 


    <bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" id="sessionFactory" lazy-init="true"> 
     <property name="dataSource" ref="dataSource"/> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.cache.use_second_level_cache">false</prop> 
       <prop key="hibernate.cache.use_query_cache">false</prop> 
       <prop key="hibernate.show_sql">false</prop> 
      </props> 
     </property> 

    </bean> 
</beans> 

Wenn die Anwendung läuft ich die unten Ausnahme erhalten:

- <Tool failed: Error creating bean with name 'transactionManager' defined in class path resource [pmBootstrapConfigs.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [pmBootstrapConfigs.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set> 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [pmBootstrapConfigs.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [pmBootstrapConfigs.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1475) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1220) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [pmBootstrapConfigs.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) 
    ... 17 more 
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104) 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71) 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) 
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930) 
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372) 
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454) 
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) 
    ... 24 more 

wenn ich <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> ausdrücklich auf die Hibernate-Eigenschaften hinzufügen es anfängt zu arbeiten.

Die häufigste Antwort, die online verfügbar ist, besteht darin, dass bei der Verbindung mit der DB ein Problem auftritt. Also habe ich versucht, ein separates Stück Code zu schreiben, um mit den gleichen Details auf die DB zuzugreifen, und es hat funktioniert. Weiß nicht, was das Problem ist.

Antwort

1

In der XML-Spring-Konfiguration, müssen Sie aktualisieren:

<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" id="sessionFactory" lazy-init="true"> 
     <property name="dataSource" ref="dataSource"/> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.cache.use_second_level_cache">false</prop> 
       <prop key="hibernate.cache.use_query_cache">false</prop> 
       <prop key="hibernate.show_sql">false</prop> 
       <!-- HERE THE DIALECT CONFIGURATION --> 
      </props> 
     </property> 

    </bean> 

Von Hibernate documentation Sie den Dialekt, wie folgend müssen:

  • Ein Dialekt für Microsoft SQL Server 2008 mit JDBC-Treiber 3.0 und oben

<prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</prop>

  • Ein Dialekt für Microsoft SQL Server 2000 und 2005

<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>

+0

Wir haben mehrere DB je nach Kunde, es kann eine Oracle-Db, SQL Db oder db2 sein. Soweit ich gelesen habe, interpretiert Hibernate automatisch den korrekten Dialekt vom Treiber. Daher können wir den Dialekt nicht fest codieren, da er für verschiedene Umgebungen unterschiedlich sein wird. – Sid

+0

Einer der Links, die ich durchging: http://stackoverflow.com/questions/26548505/org-hibernate-hibernateexception-access-to-dialectsolutioninfo-cannot-n-null – Sid

Verwandte Themen