Java Hibernate映射不时停止工作

Java Hibernate映射不时停止工作,java,spring,hibernate,Java,Spring,Hibernate,我正在编写服务器应用程序,并使用tomcat、gradle和hibernate/spring将一些实体映射到mysql数据库。每次我启动tomcat时,应用程序都会运行一段时间,最长可达5天,但随后开始对每个sql查询抛出异常,直到我再次重新启动tomcat。以下是异常堆栈,它始终是相同的: could not extract ResultSet org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(Stan

我正在编写服务器应用程序,并使用tomcat、gradle和hibernate/spring将一些实体映射到mysql数据库。每次我启动tomcat时,应用程序都会运行一段时间,最长可达5天,但随后开始对每个sql查询抛出异常,直到我再次重新启动tomcat。以下是异常堆栈,它始终是相同的:

could not extract ResultSet
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91)
org.hibernate.loader.Loader.getResultSet(Loader.java:2066)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
org.hibernate.loader.Loader.doQuery(Loader.java:910)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
org.hibernate.loader.Loader.doList(Loader.java:2554)
org.hibernate.loader.Loader.doList(Loader.java:2540)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
org.hibernate.loader.Loader.list(Loader.java:2365)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1682)
org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)
以下是我的xml配置文件的一部分:

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

<tx:annotation-driven transaction-manager="transactionManager"/>
<context:annotation-config />
<context:component-scan base-package="entertainment.service" />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost/mmd?characterEncoding=UTF-8" />
    <property name="username" value="root" />
    <property name="password" value="plannidev" />

    <!--Configuration-->
    <property name="validationQuery" value="SELECT 1" />
    <property name="validationQueryTimeout" value="60" />
    <property name="testOnBorrow" value="true" />
    <property name="removeAbandoned" value="true" />
    <property name="removeAbandonedTimeout" value="60" />

    <property name="initialSize" value="8" />
    <property name="maxActive" value="10" />
    <property name="maxIdle" value="10" />
    <property name="minIdle" value="0" />
    <property name="maxWait" value="10000" />

    <property name="timeBetweenEvictionRunsMillis" value="28800000" /> <!--8 hours-->
    <property name="testWhileIdle" value="true" />

</bean>

<bean id="sessionFactory"
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean ">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
           <!-- my entity classes --> 
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="show_sql">true</prop>
            <prop key="format_sql">true</prop>
            <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> -->
            <prop key="connection.pool_size">10</prop>
            <prop key="hibernate.enable_lazy_load_no_trans">true</prop>
            <prop key="hibernate.connection.charSet">utf8</prop>
            <prop key="hibernate.connection.characterEncoding">utf8</prop>
            <prop key="hibernate.connection.useUnicode">true</prop>
        </props>
    </property>
</bean>

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

<!-- my beans here-->

</beans>

不幸的是,我有很多实体类在这里发布代码。也许有人能帮我看看我的配置是否一切正常?或者有人面临类似的问题?提前感谢大家。

您可能会遇到此错误,因为hibernate无法将值从db映射到您的模型,当您尝试将字符串列绑定到实体中的int属性或绑定无效的枚举值等时,可能会发生此错误


尝试使用hbm2dll验证值运行hibernate

您可以发布完整的堆栈跟踪吗?以及导致错误的查询?每个sql查询都以相同的StackTrace结束。我发现,如果我在手动创建的架构中设置了create,则在自动创建的架构中标记为外键的某些列没有标记为外键,这可能是原因吗?我不这么认为,当外键引用的实体不存在时,您将得到异常,但它将是EntityNotFoundException当您在验证模式下运行带有hbm2dll的hibernate时,没有任何异常?没有,一切都很好。我已经添加了外键约束,在那之后,它运行了1.5天,没有这样的异常。但它已经运行了几天,但随后又开始抛出异常。我会看得更远,希望能有所帮助
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'com.factual:factual-java-driver:1.8.8'
compile 'com.google.code.gson:gson:2.3.1'
compile 'org.jsoup:jsoup:1.8.1'
compile 'de.u-mass:lastfm-java:0.1.2'
compile 'com.sun.jersey:jersey-server:1.19'
compile 'junit:junit:4.12'
compile 'org.hibernate:hibernate-core:4.3.8.Final'
compile 'org.hibernate:hibernate-entitymanager:4.3.8.Final'
compile 'org.hibernate:hibernate-validator:5.1.3.Final'
compile 'org.hibernate:hibernate-commons-annotations:3.2.0.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
compile 'org.jboss.logging:jboss-logging:3.2.1.Final'
compile 'com.sun.jersey:jersey-core:1.19'
compile 'com.sun.jersey:jersey-server:1.19'
compile 'com.sun.jersey:jersey-servlet:1.19'

compile 'jstl:jstl:1.2'
compile 'com.sun.jersey:jersey-json:1.19'
compile 'mysql:mysql-connector-java:5.1.35'
compile 'joda-time:joda-time-hibernate:1.3'
compile 'org.jadira.usertype:usertype.core:3.2.0.GA'
compile 'javax.mail:mail:1.4.7'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.javadocmd:simplelatlng:1.3.1'
compile 'com.intersult:jpa-fix:1.1'

compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'commons-logging:commons-logging:1.2'
compile 'org.apache.httpcomponents:httpasyncclient:4.1.2'
compile 'org.apache.httpcomponents:httpcore:4.4.5'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
compile 'org.apache.httpcomponents:httpcore-nio:4.4.5'
compile 'org.apache.httpcomponents:httpmime:4.5.2'
compile 'org.json:json:20160212'

compile 'org.springframework:spring-core:4.3.1.RELEASE'
compile 'org.springframework:spring-context-support:4.3.1.RELEASE'
compile 'org.springframework:spring-web:4.3.1.RELEASE'
compile 'org.springframework:spring-orm:4.3.1.RELEASE'
compile 'org.springframework:spring-tx:4.3.1.RELEASE'
compile 'org.springframework:spring-aop:4.3.1.RELEASE'

compile 'org.neo4j.driver:neo4j-java-driver:1.0.3'
compile 'org.neo4j.test:neo4j-harness:3.1.0-M05'

compile 'com.sun.jersey.contribs:jersey-spring:1.8'

compile 'commons-dbcp:commons-dbcp:1.4'

compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.apache.commons:commons-collections4:4.1'

compile 'org.liquibase:liquibase-core:3.5.1'
compile 'com.amazonaws:aws-java-sdk:1.11.26'

compile 'io.reactivex:rxjava:1.1.9'
compile 'com.restfb:restfb:1.30.0'

compile group: 'com.github.davidmoten', name: 'geo', version: '0.7.1'
compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.6.10'
compile group: 'org.springframework.retry', name: 'spring-retry', version: '1.1.2.RELEASE'

providedCompile 'javax.servlet:servlet-api:2.5'
providedCompile 'org.apache.tomcat:tomcat-jsp-api:7.0.55'

testCompile "junit:junit:4.11"
testCompile "org.mockito:mockito-all:1.9.5"

}