休眠不启动 [英] Hibernate doesn't start

查看:75
本文介绍了休眠不启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在春天有以下hibernate配置,服务器在很长时间后启动,但没有连接到DB(DB上没有模式)。因此,它提供了一个错误消息,或通过< prop key =hibernate.hbm2ddl.auto> create< / prop> 来创建模式。

I have the following hibernate config on spring and the server starts after a long time but doesn't connect to DB (no schema on DB). So It was supose to give a error message or create the schema with <prop key="hibernate.hbm2ddl.auto">create</prop>.

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method = "close"> 
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://dburl:3306"/>
    <property name="user" value="user"/>
    <property name="password" value="pass!"/>
</bean>


<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

    <property name="mappingResources">
        <list>
            <value>waf/resources/User.hbm.xml</value>
            <value>waf/resources/Post.hbm.xml</value>
            <value>waf/resources/Position.hbm.xml</value>
            <value>waf/resources/Comment.hbm.xml</value>
        </list>
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">validate</prop>
            <!-- C3P0 CONNECTION POOL -->
            <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>              
            <prop key="c3p0.acquire_increment">1</prop>             
            <prop key="c3p0.idle_test_period">100</prop>
            <prop key="c3p0.max_size">20</prop>
            <prop key="c3p0.max_statements">50</prop>
            <prop key="c3p0.min_size">1</prop>
            <prop key="c3p0.timeout">10</prop>
        </props>
    </property>
    <property name="dataSource">
        <ref bean="dataSource"/>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
    <property name="sessionFactory">
        <ref bean="sessionFactory"/>
    </property> 
</bean>

您可以帮我吗?

Can you guys help me out?

推荐答案

如果您正在使用连接池(您提到的是c3po),添加到其他人所建议的内容中,则会话Factory创建时会尝试使用连接池支持的数据源,反过来将连接到数据库来预先创建和池连接。当你说它没有连接到数据库时 - 你怎么知道的?日志中是否有错误?我已经看到,如果Hibernate会话工厂无法自行配置,它会在日志中引发错误。

Adding to what others have proposed if you are using connection pool (which you are as c3po is mentioned) then while the session Factory is created it will try to use the connection pool backed datasource which in turn will connect to database to pre-create and pool connection. When you say that it does not connect to database - how do you know that ? Is there error in logs? I have seen that if Hibernate session factory is not able to configure itself it throws an error in the logs.

这篇关于休眠不启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆