Connection cannot be null when 'hibernate.dialect' not set hibernate4 tomcat7

后端 未结 2 933
广开言路
广开言路 2021-01-16 23:09

I\'ve followed some tutorial in order to set up a web application using spring, hibernate to run on tomcat.

When trying to run my application I get the error \"Conne

相关标签:
2条回答
  • 2021-01-16 23:34

    Add this and check

    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    0 讨论(0)
  • 2021-01-16 23:52

    Piece of code from the tutorial you mentioned:

        <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>
    

    This is where hibernate.cfg.xml was specified and, also, where the dialect was put. If you have <property name="dataSource" ref="dataSource" /> for the session factory, you don't need it in the hibernate.cfg.xml. I would suggest looking again at that's tutorial source code and adjust your code accordingly.

    0 讨论(0)
提交回复
热议问题