我知道这是一个常见的问题,但没有一个解决方案适合我。下面是我的胸带。xml:
<?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>
当应用程序运行时,我得到以下异常:
- <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
如果我添加
在线上最常见的答案是连接数据库时出现了一些问题。因此,我尝试编写一段单独的代码,只需使用相同的细节访问数据库,结果成功了。我不知道问题出在哪里。
我有类似的问题,而测试MySQL 8与Hibernate-5
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="com.model"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
如果指定数据库名称,则无需设置方言。为此,您可以使用JPavendorAdapter作为org的属性。springframework。奥姆。jpa。LocalContainerEntityManagerFactoryBean或HibernatePersistenceProvider(对于低于5的hibernate版本),如果是microsoft sql server
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="database" value="SQL_SERVER" />
</bean>
</property>
在XML Spring配置中,必须更新:
<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>
从Hibernate文档中,必须提供如下方言:
Microsoft SQL Server 2000和2005的方言
问题内容: 我正在尝试运行一个通过spring-jpa使用hibernate模式的spring-boot应用程序,但出现此错误: 我的文件是这样的: 我的hibernate配置是(方言配置位于此类的最后一个方法中): 我在这里做错了什么? 问题答案: 首先删除所有配置,Spring Boot会为你启动它。如果你确实需要a 而不是。 确保你的类路径中有一个,然后添加以下属性。 如果你确实需要访问,并
问题内容: 我正在使用Hibernate最新版本。 我的文件内容: 创建SessionFactory的实用程序类: 在我的方法中使用它时,出现以下异常: 我尝试了很多选择,并寻找了在线资源,hibernate文档,但找不到此处缺少的内容。任何帮助表示赞赏。 问题答案: 最终能够解决问题,问题在于创建方法。 首先,正式文件是第一个要去的地方,我必须说,Hibernate正式文件似乎没有更新为最新版本
我有一个Spring Boot JPA应用程序。每当我尝试运行它时,它都会失败: 我已经在这里查看了相关问题,但大多数问题似乎与数据库尚未启动、凭据不正确等问题有关。但是,我能够很好地连接到PSQL客户端,所以这不是问题所在。我已经尝试过使用和不使用application.properties中指定的平台和驱动程序: 此外,在错误之上,应用程序实际上打印出以下内容: 问题可能是什么?这个应用程序实
问题内容: 我正在尝试运行一个通过spring-jpa使用hibernate模式的spring-boot应用程序,但出现此错误: 我的pom.xml文件是这样的: 我的hibernate配置是(方言配置位于此类的最后一个方法中): 我在这里做错了什么? 问题答案: 首先删除所有配置,Spring Boot将为您启动它。如果您确实需要a 而不是add 。 确保您的类路径中有一个,并添加以下属性。 如
使用Maven创建Hibernate测试项目。 知道问题出在哪里吗?? CustomerModel类:
我正在和几个人一起为学校做一个项目。当我运行我的项目时,我得到了一堆错误,这些错误似乎是由以下原因引起的:当“hibernate”时,对DialectResolutionInfo的访问不能为空。未设置方言。 这是我的砰.xml: 这是我的错误报告: 这是因为缺少家属而引起的问题吗?我是个java新手,我自己似乎找不到问题。