在对Postgresql数据库

时间:2015-07-29 07:55:07

标签: java spring hibernate postgresql

我有一个使用spring / hibernate / jparepository连接到Postgresql 9.3.9 db的应用程序。 它执行findAll()查询,读取整个表(20行...),连接很少。 在测试数据库中填充测试数据的服务器上运行完美。 在生产数据库中填充生产数据的另一台服务器上,应用程序在执行“select”查询后挂起并开始刻录cpu。 如果我在pgadmin3上粘贴相同的查询,它将在22ms内在生产数据库上执行。 所以我在想一个java / jdbc / hibernate错误,但我已经在使用最新版本了。

我该如何调试?

Java DAO

public interface SitesRepository extends JpaRepository<Sites, Integer> {
    @EntityGraph(value = "tutto", type = EntityGraphType.LOAD)
    List<Sites> findAll();
}

PU

<persistence-unit name="archeologPU">
  <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>    
</persistence-unit>

春天背景

<context:annotation-config />
    <context:component-scan base-package="it.giammar.situumlocalizator" />
    <jpa:repositories base-package="it.giammar.situumlocalizator" />



    <!--bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
        <property name="driverClassName" value="org.postgresql.Driver" /> <property 
        name="url" value="jdbc:postgresql://localhost:5432/archeolog" /> <property 
        name="username" value="postgres" /> <property name="password" value="postgres" 
        /> </bean -->

    <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
        <property name="maximumPoolSize" value="1000" />
        <property name="dataSourceProperties">
            <props>
                <!--prop key="url">jdbc:postgresql://localhost:5432/archeolog</prop-->
                <prop key="user">postgres</prop>
                <prop key="password">postgres</prop>
                <prop key="databaseName">archeolog</prop>
                <prop key="serverName">localhost</prop>
            </props>
        </property>
        <property name="dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource" />
    </bean>

    <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
        <constructor-arg ref="hikariConfig" />
    </bean>
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        p:dataSource-ref="dataSource">

    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven proxy-target-class="true"
        transaction-manager="transactionManager" />

查询 DEBUG org.hibernate.SQL - select sites0_.id as id1_6_0_, coverings2_.id as id1_0_1_, publicacce3_.id as id1_5_2_, typeofsett5_.id as id1_11_3_, iso31662x6_.alpha4code as alpha1_3_4_, sites0_.code as code2_6_0_, sites0_.description as descript3_6_0_, sites0_.detectionTecnique as detectio4_6_0_, sites0_.langCode_alpha4code as langCod15_6_0_, sites0_.lat as lat5_6_0_, sites0_.location as location6_6_0_, sites0_.lon as lon7_6_0_, sites0_.name as name8_6_0_, sites0_.ownershipAndManagement as ownershi9_6_0_, sites0_.period as period10_6_0_, sites0_.periodOfExcavation as periodO11_6_0_, sites0_.priorityValue as priorit12_6_0_, sites0_.publicAccess_id as publicA16_6_0_, sites0_.siteAuthor as siteAut13_6_0_, sites0_.siteURL as siteURL14_6_0_, protection7_.Sites_id as Sites_id1_6_2__, protection7_.typeOfSiteProtection_code as typeOfSi2_9_2__, protection7_.levels_id as levels_i3_9_2__, coverings2_.areaNumber as areaNumb2_0_1_, coverings2_.coveringArea as covering3_0_1_, coverings2_.coveringAuthor as covering4_0_1_, coverings2_.criticalArea as critical5_0_1_, coverings2_.date as date6_0_1_, coverings2_.item as item7_0_1_, coverings2_.note as note8_0_1_, coverings2_.previousCode as previous9_0_1_, coverings2_.priority as priorit10_0_1_, coverings2_.sites_id as sites_i11_0_1_, coverings2_.typology_id as typolog12_0_1_, coverings2_.wall_id as wall_id13_0_1_, coverings1_.Sites_id as Sites_id1_6_0__, coverings1_.coverings_id as covering2_7_0__, protection7_.Sites_id as Sites_id1_6_2__, protection7_.typeOfSiteProtection_code as typeOfSi2_9_2__, protection7_.levels_id as levels_i3_9_2__, publicacce3_.description as descript2_5_2_, protection7_.Sites_id as Sites_id1_6_2__, protection7_.typeOfSiteProtection_code as typeOfSi2_9_2__, protection7_.levels_id as levels_i3_9_2__, typeofsett5_.description as descript2_11_3_, settlement4_.Sites_id as Sites_id1_6_1__, settlement4_.settlements_id as settleme2_8_1__, protection7_.Sites_id as Sites_id1_6_2__, protection7_.typeOfSiteProtection_code as typeOfSi2_9_2__, protection7_.levels_id as levels_i3_9_2__, iso31662x6_.category as category2_3_4_, iso31662x6_.name as name3_3_4_, iso31662x6_.subdivision as subdivis4_3_4_, protection7_.Sites_id as Sites_id1_6_2__, protection7_.typeOfSiteProtection_code as typeOfSi2_9_2__, protection7_.levels_id as levels_i3_9_2__ from Sites sites0_ left outer join Sites_Coverings coverings1_ on sites0_.id=coverings1_.Sites_id left outer join Coverings coverings2_ on coverings1_.coverings_id=coverings2_.id left outer join PublicAccess publicacce3_ on sites0_.publicAccess_id=publicacce3_.id left outer join Sites_TypeOfSettlement settlement4_ on sites0_.id=settlement4_.Sites_id left outer join TypeOfSettlement typeofsett5_ on settlement4_.settlements_id=typeofsett5_.id left outer join Iso31662 iso31662x6_ on sites0_.langCode_alpha4code=iso31662x6_.alpha4code left outer join Sites_protections protection7_ on sites0_.id=protection7_.Sites_id

最后,如果你还等待,junit test会出现内存不足错误(请注意表中有22行):

  

10:38:31.960 [main] DEBUG o.s.orm.jpa.JpaTransactionManager -   参与交易失败 - 将现有交易标记为   rollback-only 10:38:31.961 [main] DEBUG   o.s.orm.jpa.JpaTransactionManager - 设置JPA事务   EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@745e6f01]   rollback-only 10:38:31.961 [main] DEBUG   o.s.orm.jpa.JpaTransactionManager - 启动事务回滚   10:38:31.961 [main] DEBUG o.s.orm.jpa.JpaTransactionManager - Rolling   返回EntityManager上的JPA事务   [org.hibernate.jpa.internal.EntityManagerImpl@745e6f01] 10:38:31.962   [main] DEBUG o.h.e.t.spi.AbstractTransactionImpl - 回滚   10:38:31.962 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - Rolling JDBC   连接10:38:31.962 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction -   重新启用autocommit 10:38:31.985 [main] DEBUG   o.s.orm.jpa.JpaTransactionManager - 关闭JPA EntityManager   [org.hibernate.jpa.internal.EntityManagerImpl@745e6f01]之后   交易10:38:31.986 [主要] DEBUG   o.s.o.jpa.EntityManagerFactoryUtils - 关闭JPA EntityManager   10:38:31.988 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Releasing   JDBC连接10:38:31.989 [main] DEBUG   o.h.e.j.i.LogicalConnectionImpl - 发布的JDBC连接   10:38:31.991 [main] INFO o.s.t.c.t.TransactionContext - 回滚   测试上下文的事务[DefaultTestContext @ 379bc1bf testClass =   TestPersistence,testInstance =   it.giammar.situumlocalizator.TestPersistence@52ccff1e,testMethod =   testLeggiSites @ TestPersistence,testException =   java.lang.OutOfMemoryError:Java堆空间,   mergedContextConfiguration = [MergedContextConfiguration @ 1081350a   testClass = TestPersistence,locations =   '{file:src / main / webapp / WEB-INF / spring-context.xml}',classes ='{}',   contextInitializerClasses ='[]',activeProfiles ='{}',   propertySourceLocations ='{}',propertySourceProperties ='{}',   contextLoader =   'org.springframework.test.context.support.DelegatingSmartContextLoader',   parent = [null]]]。

0 个答案:

没有答案