JPA Hibernate通信链路故障错误

时间:2013-02-21 23:09:55

标签: spring hibernate jpa spring-mvc heroku

我遇到了JPA和Hibernate的真正问题它有时会让通信链接失败并不确定为什么会发生这种情况经常不确定为什么它是一个环境问题配置问题无法让我真正理解我会爱上其他人人们就此问题提出意见并希望指出我正确的方向

这是堆栈跟踪

 21:41:34,726 DEBUG SqlExceptionHelper:139 - Communications link failure
 2013-02-21T21:41:34+00:00 app[web.1]: 
 2013-02-21T21:41:34+00:00 app[web.1]: The last packet successfully received from the  server was 79,581 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago. [n/a]
 2013-02-21T21:41:34+00:00 app[web.1]: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  2013-02-21T21:41:34+00:00 app[web.1]: 
 2013-02-21T21:41:34+00:00 app[web.1]: The last packet successfully received from the server was 79,581 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
 2013-02-21T21:41:34+00:00 app[web.1]:  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

的pom.xml

<properties>
  <org.springframework.version>3.1.1.RELEASE</org.springframework.version>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>2.2.8</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.20</version>
</dependency>
<dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
</dependency>
<dependency>
    <groupId>com.github.jsimone</groupId>
    <artifactId>webapp-runner</artifactId>
    <version>7.0.27.1</version>
    <scope>provided</scope>
</dependency>


<!-- Tiles dependency -->
<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-core</artifactId>
    <version>2.2.1</version>
</dependency>

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-jsp</artifactId>
    <version>2.2.1</version>
</dependency>
<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-api</artifactId>
    <version>2.2.1</version>
</dependency>
<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-servlet</artifactId>
    <version>2.2.1</version>
</dependency>
<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-template</artifactId>
    <version>2.2.1</version>
</dependency>

<!-- Security -->
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>3.1.3.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.1.3.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>3.1.3.RELEASE</version>
</dependency>

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.0.0.GA</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.1.4.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.3.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>4.1.4.Final</version>
</dependency>
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.1</version>
</dependency>

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.11</version>
</dependency>
<!-- Junit API -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.9.5</version>
</dependency>


<!-- JavaMail API -->
<dependency>
    <groupId>javamail</groupId>
    <artifactId>javamail</artifactId>
    <version>1.3.3</version>
</dependency>
<!-- Java Activation -->
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>
<!-- JavaMail extension -->
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.6-rc1</version>
</dependency>
<!-- LOG4J -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.6</version>
</dependency>

<!-- The newrelic-agent.jar dependency. -->
<dependency>
    <groupId>com.newrelic.agent.java</groupId>
    <artifactId>newrelic-agent</artifactId>
    <version>2.12.0</version>
    <scope>provided</scope>
</dependency>
<!-- The newrelic-api.jar dependency. -->
<dependency>
    <groupId>com.newrelic.agent.java</groupId>
    <artifactId>newrelic-api</artifactId>
    <version>2.12.0</version>
    <scope>compile</scope>
</dependency>
<!-- The newrelic-java.zip dependency. -->
<dependency>
    <groupId>com.newrelic.agent.java</groupId>
    <artifactId>newrelic-java</artifactId>
    <version>2.12.0</version>
    <scope>provided</scope>
    <type>zip</type>
</dependency>
<dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.5.4</version>
</dependency>
</dependencies>

<build>
<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.2</version>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.6</version>
        <executions>
            <execution>
                <id>unpack-zip</id>
                <phase>package</phase>
                <goals>
                    <goal>unpack-dependencies</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>com.newrelic.agent.java</groupId>
                            <artifactId>newrelic-java</artifactId>
                            <version>theVersion</version>
                            <type>zip</type>
                            <overWrite>true</overWrite>
                            <outputDirectory>target</outputDirectory>
                            <destFileName>newrelic</destFileName>
                        </artifactItem>
                    </artifactItems>
                    <outputDirectory>/newrelic</outputDirectory>
                </configuration>
            </execution>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>copy</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>com.github.jsimone</groupId>
                            <artifactId>webapp-runner</artifactId>
                            <version>7.0.27.1</version>
                            <destFileName>webapp-runner.jar</destFileName>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

的persistence.xml

  <persistence-unit name="dataSource">
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property key="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
            <property key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property key="hibernate.show_sql">true</property>
            <property key="hibernate.hbm2ddl.auto">verify</property>
            <property key="hibernate.current_session_context_class">thread</property>
            <property key="hibernate.c3p0.acquire_increment">1</property>
            <property key="hibernate.c3p0.min_size">5</property>
            <property key="hibernate.c3p0.max_size">20</property>
            <property key="hibernate.c3p0.timeout">5000</property>
            <property key="hibernate.c3p0.max_statements">100</property>
            <property key="hibernate.c3p0.idle_test_period">3000</property>
            <property key="hibernate.c3p0.testConnectionOnCheckout">true</property>
            <property key="hibernate.c3p0.acquireRetryAttempts">1</property>
    </properties>

的applicationContext.xml

  <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://' + @dbUrl.getHost() + @dbUrl.getPath() }" />
    <property name="username" value="#{ @dbUrl.getUserInfo().split(':')[0] }" />
    <property name="password" value="#{ @dbUrl.getUserInfo().split(':')[1] }" />
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
</bean>

0 个答案:

没有答案