sky82917042
2009-07-22 11:41
浏览 513
已采纳

hibernate配置sql server方言问题

请教各位达人们
我已经在配置文件中指明了sql server方言
可是在tomcat启动时候还是报错

jdbc.properties属性文件内容:

Properties file with JDBC-related settings.

Applied by PropertyPlaceholderConfigurer from "dataAccessContext-local.xml".

Targeted at system administrators, to avoid touching the context XML files.

jdbc.driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc.url=jdbc:microsoft:sqlserver//localhost:1433;databasename=BusinessEnglish
jdbc.username=sa
jdbc.password=sa

hibernate.show_sql=true
hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect

spring配置文件
<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">




WEB-INF/jdbc.properties


class="org.apache.commons.dbcp.BasicDataSource">




class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">




${hibernate.show_sql}

${hibernate.dialect}





com/dfyx/pojo/Student.hbm.xml




class="org.springframework.orm.hibernate3.HibernateTransactionManager">

tx:attributes


/tx:attributes
/tx:advice

aop:config
expression="execution(* com.pk.spring.service.impl.*.*(..))" />


/aop:config

报错内容:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iStudentDao' defined in ServletContext resource [/WEB-INF/springConfig/applicationContext_demo.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 ServletContext resource [/WEB-INF/springConfig/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Hibernate Dialect must be explicitly set

[b]问题补充:[/b]

applicationContext_demo.xml文件内容:
<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<bean id="iStudentDao" class="com.dfyx.dao.impl.StudentDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="studentService"
    class="com.dfyx.service.impl.StudentServiceImpl">
    <property name="studentDao" ref="iStudentDao"></property>
</bean>

<!-- 为了给Action注入Service, 添加的新的bean
<bean name="/emp" class="com.pk.spring.web.action.EmpAction">
    <property name="empSerivce" ref="empService"></property>
</bean>
 -->

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • 安迪 2009-07-22 11:54
    已采纳

    applicationContext_demo.xml这个文件贴出来,这里边的"iStudentDao"配置部分错误了!

    点赞 评论
  • wanghaolovezlq 2009-07-22 11:52

    [color=red]hibernate.dialect=org.hibernate.dialect.SQLServerDialect [/color]

    点赞 评论
  • iteye_20589 2009-07-22 11:52

    [quote]我已经在配置文件中指明了sql server方言
    可是在tomcat启动时候还是报错 [/quote]
    这不是你指明的方言有问题..而是程序有错..
    比如:网上的代码,
    错误的代码就会报Hibernate Dialect must be explicitly set
    [code="java"]正确代码如下:

    public PsonOperate(){
    Configuration config=new Configuration();
    SessionFactory factory=config.configure().buildSessionFactory();
    this.session=factory.openSession();
    }

    出错代码如下:

    public PsonOperate(){
    Configuration config=new Configuration();
    SessionFactory factory=config.buildSessionFactory();//少了configure()
    this.session=factory.openSession();
    }[/code]

    点赞 评论
  • iteye_20589 2009-07-22 12:37

    看一下是不是] 错误.
    把[quote]
    ${hibernate.dialect}
    [/quote]
    改成
    [code="java"]
    org.hibernate.dialect.SQLServerDialect
    [/code]


    [code="java"]
    ${hibernate.dialect}
    [/code]
    同时把下面
    hibernate.dialect=[color=red]net.sf.hibernate.dialect.SQLServerDialect [/color]
    改成hibernate.dialect=org.hibernate.dialect.SQLServerDialect

    点赞 评论
  • fdsafds 2009-07-22 13:25

    net.sf.hibernate.dialect.SQLServerDialect
    确认这个类是否在你的Hibernate jar 包中

    hibernate 3应该是这样的
    hibernate.dialect=org.hibernate.dialect.SQLServerDialect

    没有sf包了,确认一下

    点赞 评论
  • pjuneye 2009-07-22 13:49

    Hibernate版本不一致吧.LZ的配置老早了,请LZ确认对应版本的配置.

    点赞 评论

相关推荐 更多相似问题