【问题标题】:The user must supply a JDBC connection用户必须提供 JDBC 连接
【发布时间】:2014-09-25 16:22:27
【问题描述】:

我有一个DispactherServlet.xml 文件,它的休眠文件配置为

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingResources">
        <list>
            <value>com/dibya/hbm/resource/model.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.username">root</prop>
            <prop key="hibernate.password"></prop>
            <prop key="hibernate.url">jdbc:mysql://localhost/test</prop>
            <prop key="hibernate.driver_class">com.mysql.jdbc.Driver</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
        </props>
    </property>
</bean>

<bean id = "hibernateTemplate" class = "org.springframework.orm.hibernate3.HibernateTemplate">
    <property name = "persister">
        <ref bean = "sessionFactory"/>
    </property>
</bean>

在我的控制器中,我有

@RequestMapping(value = "Hello.htm")
public String HelloWorld(Model model) {
    boolean is = persister.isAllowCreate();

    Person person = new Person();
    person.setName("dibya");
    persister.saveOrUpdate(person);

    System.out.println("This is called"+is);
    return "HelloWorld";
}

我收到此错误消息:

HTTP Status 500 - Request processing failed; nested exception is java.lang.UnsupportedOperationException: The user must supply a JDBC connection

请告诉我我忘了添加什么。

【问题讨论】:

    标签: java spring hibernate jdbc


    【解决方案1】:

    你可以这样配置:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="hibernateProperties">
                <props>
    
                    <prop key="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</prop>
                    <prop key="hibernate.connection.url">jdbc:hsqldb:file:/local/hsqldb</prop>
                    <prop key="hibernate.connection.username">sa</prop>
                    <prop key="hibernate.connection.password"></prop>
    
    
                    <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                    <prop key="hibernate.show_sql">${gloss.database.hibernate.show_sql}</prop>
                    <prop key="hibernate.order_inserts">true</prop>
                    <prop key="hibernate.order_updates">true</prop>
                    <prop key="hibernate.jdbc.batch_size">100</prop>
                    <prop key="hibernate.hbm2ddl.auto">validate</prop>
    
                </props>
            </property>
    
            <property name="mappingResources">
                <list>
                    <value>com/core/domain/User.hbm.xml</value>
                </list>
            </property>
        </bean>
    

    【讨论】:

      【解决方案2】:

      您的休眠配置文件使用了错误的参数名称。正确的参数名称如下:

      hibernate.connection.driver_class
      hibernate.connection.url
      hibernate.connection.username
      hibernate.connection.password
      hibernate.dialect
      hibernate.show_sql
      

      更正您的参数名称,然后重试。

      编辑:有关参数名称的详细列表,请参阅此链接:http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-05
        • 2014-06-07
        • 2014-07-26
        • 2016-12-04
        • 2015-12-04
        • 1970-01-01
        • 2017-07-02
        相关资源
        最近更新 更多