Java hibernate条件列表后的Postgresql无限循环

Java hibernate条件列表后的Postgresql无限循环,java,spring,hibernate,postgresql,Java,Spring,Hibernate,Postgresql,我已经被数据库问题困扰了好几天了。应用程序在特定的hibernate条件后挂起。list()。正是通过以下stacktrace: java.net.SocketInputStream.read(byte[], int, int) org.postgresql.core.VisibleBufferedInputStream.readMore(int) org.postgresql.core.VisibleBufferedInputStream.ensureBytes(int) org.postgr

我已经被数据库问题困扰了好几天了。应用程序在特定的hibernate条件后挂起。list()。正是通过以下stacktrace:

java.net.SocketInputStream.read(byte[], int, int)
org.postgresql.core.VisibleBufferedInputStream.readMore(int)
org.postgresql.core.VisibleBufferedInputStream.ensureBytes(int)
org.postgresql.core.VisibleBufferedInputStream.read()
org.postgresql.core.PGStream.ReceiveChar()
org.postgresql.core.v3.QueryExecutorImpl.processResults(ResultHandler, int)
org.postgresql.core.v3.QueryExecutorImpl.execute(Query, ParameterList, ResultHandler, int, int, int)
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(Query, ParameterList, int)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(int)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery()
org.hibernate.internal.CriteriaImpl.list()
经过一些研究和测试,我发现问题不是阻塞查询,而是永远执行的查询

它是一个java spring应用程序,具有以下sessionFactory和事务管理器配置:

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbc:postgresql://localhost:5432/database" />
    <property name="username" value="username" />
    <property name="password" value="password" />
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.myapp.domain" /> 
    <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

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

底层数据库是PostgreSQL,下面是当前的hibernate配置

<hibernate-configuration>
    <session-factory>       
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <property name="hbm2ddl.auto">none</property>
        <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <property name="cache.use_query_cache">true</property>

        <property name="hibernate.transaction.factory_class">
        org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="show_sql">false</property>
        <property name="format_sql">true</property>
        <property name="use_sql_comments">false</property>
        <property name="order_updates">true</property>
    </session-factory>
</hibernate-configuration>

org.hibernate.dialogue.PostgreSqlDialogue
没有一个
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
符合事实的
符合事实的
org.hibernate.transaction.jdbc事务工厂
错误的
符合事实的
错误的
符合事实的
准则中的关键领域是:

private void fillEmptyNames() throws CablewatchException {
    List<Device> devicesList = deviceDao.getDevices();
    if (devicesList != null) {
        for (Device device : devicesList {
            String name = deviceDao.getDeviceName(device.getModule().getObjectIdentifier(), device.getSubrack(), device.getSlot());
    ...
        }
    }
}
private void fillEmptyNames()引发CablewatchException{
List DeviceList=deviceDao.getDevices();
如果(设备列表!=null){
用于(设备:设备列表){
字符串名称=deviceDao.getDeviceName(device.getModule().getObjectIdentifier(),device.getSubrack(),device.getSlot());
...
}
}
}
应用程序挂起第二个dao函数“getDeviceName”,其实现如下:

@Transactional(timeout=30)
public String getDeviceName(long moduleId, int subrackNr, int slotNr) throws CablewatchException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Device.class).add(Restrictions.eq("module.objectIdentifier", moduleId)).add(Restrictions.eq("subrack",subrackNr)).add(Restrictions.eq("slot",slotNr)).addOrder(Order.desc("objectIdentifier")).setMaxResults(1);

    List<Device> devicesList = criteria.list();

    if (devicesList != null && !devicesList.isEmpty() && devicesList.get(0) instanceof Device) {
        Device device = devicesList.get(0);
        return device.getName();
    }
    return null;
}
事务性(超时=30) 公共字符串getDeviceName(long moduleId、int subrackNr、int slotNr)引发CablewatchException{ Criteria Criteria=sessionFactory.getCurrentSession().createCriteria(Device.class).add(Restrictions.eq(“module.objectIdentifier”,moduleId)).add(Restrictions.eq(“subrack”,subrackNr)).add(Restrictions.eq(“slot”,slotNr)).addOrder(Order.desc(“objectIdentifier”).setMaxResults(1); 列表设备列表=标准。列表(); if(DeviceList!=null&&!DeviceList.isEmpty()&&DeviceList.get(0)设备实例){ 设备设备=设备列表。获取(0); 返回device.getName(); } 返回null; } 我遇到的另一个细节是,同样的段落在Windows下运行良好,因此目前这个问题只发生在Linux上

更新: 生成的查询是:

select
    this_.objectIdentifier as objectId1_0_9_,
    this_.ackId as ackId11_0_9_,
    this_.alarmInfoId as alarmIn12_0_9_,
    this_.cleared as cleared2_0_9_,
    this_.clearedTime as clearedT3_0_9_,
    this_.logIndex as logIndex4_0_9_,
    this_.module as module5_0_9_,
    this_.neId as neId13_0_9_,
    this_.occurenceTime as occurenc6_0_9_,
    this_.serial as serial7_0_9_,
    this_.severityId as severit14_0_9_,
    this_.slot as slot8_0_9_,
    this_.subrack as subrack9_0_9_,
    this_.value as value10_0_9_,
    acknowledg2_.objectIdentifier as objectId1_2_0_,
    acknowledg2_.comment as comment2_2_0_,
    acknowledg2_.username as username3_2_0_,
    alarminfo3_.objectIdentifier as objectId1_1_1_,
    alarminfo3_.cw_alarmMessage as cw_alarm2_1_1_,
    alarminfo3_.cw_alarmOid as cw_alarm3_1_1_,
    ne4_.OBJECTIDENTIFIER as OBJECTID1_8_2_,
    ne4_.cw_neActive as cw_neAct2_8_2_,
    ne4_.cw_neCategory as cw_neCat3_8_2_,
    ne4_.cw_neFirmware as cw_neFir4_8_2_,
    ne4_.cw_neHasWebInterface as cw_neHas5_8_2_,
    ne4_.cw_neInetAddress as cw_neIne6_8_2_,
    ne4_.cw_neInfo as cw_neInf7_8_2_,
    ne4_.cw_neMacAddress as cw_neMac8_8_2_,
    ne4_.cw_neModel as cw_neMod9_8_2_,
    ne4_.cw_neName as cw_neNa10_8_2_,
    ne4_.cw_neSerial as cw_neSe11_8_2_,
    ne4_.cw_neSysDescription as cw_neSy12_8_2_,
    ne4_.cw_neType as cw_neTy13_8_2_,
    ne4_.cw_installationDate as cw_inst14_8_2_,
    ne4_.cw_instance as cw_inst15_8_2_,
    ne4_.cw_lastAlarmLogIndex as cw_last16_8_2_,
    ne4_.cw_locationId as cw_loca19_8_2_,
    ne4_.cw_readCommunity as cw_read17_8_2_,
    ne4_.cw_severityId as cw_seve20_8_2_,
    ne4_.cw_writeCommunity as cw_writ18_8_2_,
    location5_.objectIdentifier as objectId1_5_3_,
    location5_.cw_imageName as cw_image2_5_3_,
    location5_.cw_locationCity as cw_locat3_5_3_,
    location5_.cw_locationCode as cw_locat4_5_3_,
    location5_.cw_locationContact as cw_locat5_5_3_,
    location5_.cw_locationDescription1 as cw_locat6_5_3_,
    location5_.cw_locationDescription2 as cw_locat7_5_3_,
    location5_.cw_locationName as cw_locat8_5_3_,
    location5_.cw_locationStreet as cw_locat9_5_3_,
    location5_.cw_locationType as cw_loca10_5_3_,
    location5_.cw_parentLocationId as cw_pare11_5_3_,
    location5_.cw_severityId as cw_seve12_5_3_,
    location5_.cw_sublocationSeverityId as cw_subl13_5_3_,
    location6_.objectIdentifier as objectId1_5_4_,
    location6_.cw_imageName as cw_image2_5_4_,
    location6_.cw_locationCity as cw_locat3_5_4_,
    location6_.cw_locationCode as cw_locat4_5_4_,
    location6_.cw_locationContact as cw_locat5_5_4_,
    location6_.cw_locationDescription1 as cw_locat6_5_4_,
    location6_.cw_locationDescription2 as cw_locat7_5_4_,
    location6_.cw_locationName as cw_locat8_5_4_,
    location6_.cw_locationStreet as cw_locat9_5_4_,
    location6_.cw_locationType as cw_loca10_5_4_,
    location6_.cw_parentLocationId as cw_pare11_5_4_,
    location6_.cw_severityId as cw_seve12_5_4_,
    location6_.cw_sublocationSeverityId as cw_subl13_5_4_,
    severity7_.id as id1_15_5_,
    severity7_.cw_severityColor as cw_sever2_15_5_,
    severity7_.cw_severityName as cw_sever3_15_5_,
    severity8_.id as id1_15_6_,
    severity8_.cw_severityColor as cw_sever2_15_6_,
    severity8_.cw_severityName as cw_sever3_15_6_,
    severity9_.id as id1_15_7_,
    severity9_.cw_severityColor as cw_sever2_15_7_,
    severity9_.cw_severityName as cw_sever3_15_7_,
    severity10_.id as id1_15_8_,
    severity10_.cw_severityColor as cw_sever2_15_8_,
    severity10_.cw_severityName as cw_sever3_15_8_ 
from
    CW_ALARM this_ 
left outer join
    CW_Acknowledgment acknowledg2_ 
        on this_.ackId=acknowledg2_.objectIdentifier 
left outer join
    CW_ALARMINFO alarminfo3_ 
        on this_.alarmInfoId=alarminfo3_.objectIdentifier 
left outer join
    CW_NE ne4_ 
        on this_.neId=ne4_.OBJECTIDENTIFIER 
left outer join
    CW_LOCATION location5_ 
        on ne4_.cw_locationId=location5_.objectIdentifier 
left outer join
    CW_LOCATION location6_ 
        on location5_.cw_parentLocationId=location6_.objectIdentifier 
left outer join
    CW_SEVERITY severity7_ 
        on location6_.cw_severityId=severity7_.id 
left outer join
    CW_SEVERITY severity8_ 
        on location6_.cw_sublocationSeverityId=severity8_.id 
left outer join
    CW_SEVERITY severity9_ 
        on ne4_.cw_severityId=severity9_.id 
left outer join
    CW_SEVERITY severity10_ 
        on this_.severityId=severity10_.id 
where
    this_.neId=?
    and this_.subrack=?
    and this_.slot=?
    and this_.module<>?
order by
    this_.objectIdentifier desc limit ?
选择
此对象标识符为object1\u 0\u 9\u,
此ackId为ackId11\u 0\u 9\u,
此.alarmInfoId为alarmIn12\u 0\u 9\,
此项已清除为已清除2 0 9,
此时间为clearedT3\u 0\u 9\u,
此u.logIndex作为logIndex4 0 9,,
此模块作为模块5\u 0\u 9,
这不可能是13,0,9,,
此事件发生时间为事件6\u 0\u 9\,
此序列号为serial7\u 0\u 9\u,
这一严重性被称为严重性14 0 9,
此插槽为插槽8\u 0\u 9,
此子架作为子架9\u 0\u 9,
此值作为值10\u 0\u 9\u,
确认2。objectIdentifier为object1\u 2\u 0\,
确认2。注释为注释2\u 2\u 0\u,
确认2。用户名为username3\u 2\u 0\u,
报警信息3。对象标识符为对象1,
报警信息3。cw报警信息为cw报警2\u 1\u 1\u,
alarminfo3_uu.cw_alarmOid作为cw_alarm3_1_u1_u,
ne4。对象标识符为object1\u 8\u 2,
ne4.cw与cw-neAct2.cw一样活跃,
ne4.cw必须分类为cw必须分类3.cw必须分类为cw必须分类8.cw必须分类2,
ne4.cw\U NEU固件为cw\U neFir4\U 8\U 2,
ne4_u.cw_neHasWebInterface作为cw_neHas5_8_u2_,
ne4。cw_Neinet地址为cw_neIne6_8_2_,
ne4.cw_neInfo作为cw_neInf7_8_2_,
ne4.cw\u NECAD设计为cw\u neMac8\u 8\u 2,
ne4.cw\U neModel作为cw\U neMod9\U 8\U 2\,
ne4.cw_neName为cw_neNa10_8_2_,
ne4.cw作为cw中国11、8、2,
ne4。cw NESYS描述为cw neSy12,
ne4.cw网络类型为cw网络13.8.2,
ne4.cw安装日期为cw安装日期,
ne4_u.cw_实例作为cw_inst15_8_u2_u,
ne4.cw\u LastAlarmLoginEx为cw\u last16\u 8\u 2,
ne4.cw\U位置ID为cw\U位置19\U 8\U 2\,
ne4.cw\U readCommunity作为cw\U read17\u 8\u 2\u,
ne4.cw\u服务器为cw\u服务器20\u 8\u 2,
ne4.cw_将社区写入cw_18_8_2_,
位置5。对象标识符为对象1\u 5\u 3,
位置5_u.cw_图像名称为cw_图像2_5_3_u,
位置5。cw位置城市为cw位置3,
位置5。cw位置代码为cw位置4,
位置5。cw位置触点为cw位置5,
位置5.顺时针位置描述1为顺时针位置6.顺时针位置5.顺时针位置3,
位置5.顺时针位置描述2为顺时针位置7.顺时针位置5.顺时针位置3,
位置5_uu.cw_位置名称为cw_位置8_5_u3_u,
位置5.cw位置街道作为cw位置9.5.3,
位置5.cw\U位置类型为cw\U位置10\U 5\U 3,
location5.cw\u pare11\u 5\u 3\u的parentLocationId,
位置5.cw\u服务器为cw\u服务器12\u 5\u 3,
位置5.cw\U子位置每一个都是cw\U子位置13\U 5\U 3,
位置6。对象标识符为对象1\u 5\u 4,
位置6。cw图像名称为cw图像2\u 5\u 4\u,
位置6.cw位置与cw位置3.cw位置5.cw位置相同,
位置6。cw位置代码为cw位置4,
位置6。cw位置触点为cw位置5,
位置6.cw位置描述1为cw位置6.5.4,
位置6.顺时针位置描述2为顺时针位置7.顺时针位置5.顺时针位置4,
位置6.cw\U位置名称为cw\U位置8\U 5\U 4,
位置6.cw位置街道作为cw位置9.cw位置5.cw位置4,
位置6。cw位置类型为cw位置10\U位置5\U位置4,
location6.cw\u pare11\u 5\u 4\u的parentLocationId,
位置6.cw\u服务器为cw\u服务器12\u 5\u 4,
位置6.cw\U子位置每一个都被称为cw\U子位置13\U 5\U 4,
严重性7.id为id1\U 15\U 5,
严重性7.严重性颜色为严重性2.严重性15.严重性5,
严重性7.cw严重性名称为cw严重性3.cw严重性15.cw严重性5,
严重性8。id为id1\U 15\U 6,
严重性8.严重性颜色为严重性2.严重性15.严重性6,
严重性8.cw严重性名称为cw严重性3.cw严重性15.cw严重性6,
严重性9。id为id1\U 15\U 7,
严重性9.严重性颜色为严重性2.严重性15.严重性7,
严重性9.cw严重性名称为cw严重性3.cw严重性15.cw严重性7,
严重性10。id为id1\U 15\U 8,
严重性10。cw严重性颜色为cw严重性2.15.8,
严重性10.cw严重性名称为cw严重性3.15.8
从…起
CW_警报此_
左外连接
CW_确认确认2_
在本例中,Acknowledge.Acknowledged=Acknowledge2.objectIdentifier
左外连接
CW_AL
"Limit  (cost=25819.66..25819.66 rows=1 width=1185)"
"  ->  Sort  (cost=25819.66..25819.66 rows=1 width=1185)"
"        Sort Key: this_.objectidentifier"
"        ->  Nested Loop Left Join  (cost=0.00..25819.65 rows=1 width=1185)"
"              ->  Nested Loop Left Join  (cost=0.00..25811.37 rows=1 width=1021)"
"                    ->  Nested Loop Left Join  (cost=0.00..25803.09 rows=1 width=857)"
"                          ->  Nested Loop Left Join  (cost=0.00..25799.21 rows=1 width=693)"
"                                ->  Nested Loop Left Join  (cost=0.00..25795.33 rows=1 width=529)"
"                                      ->  Nested Loop Left Join  (cost=0.00..25793.45 rows=1 width=464)"
"                                            Join Filter: (ne4_.cw_locationid = location5_.objectidentifier)"
"                                            ->  Nested Loop Left Join  (cost=0.00..25791.22 rows=1 width=399)"
"                                                  Join Filter: (this_.neid = ne4_.objectidentifier)"
"                                                  ->  Nested Loop Left Join  (cost=0.00..25788.76 rows=1 width=225)"
"                                                        ->  Nested Loop Left Join  (cost=0.00..25780.48 rows=1 width=150)"
"                                                              Join Filter: (this_.ackid = acknowledg2_.objectidentifier)"
"                                                              ->  Seq Scan on cw_alarm this_  (cost=0.00..25779.32 rows=1 width=132)"
"                                                                    Filter: (((module)::text <> ''::text) AND (neid = 471) AND (subrack = (-1)) AND (slot = (-1)))"
"                                                              ->  Seq Scan on cw_acknowledgment acknowledg2_  (cost=0.00..1.07 rows=7 width=18)"
"                                                        ->  Index Scan using cw_alarminfo_pkey on cw_alarminfo alarminfo3_  (cost=0.00..8.27 rows=1 width=75)"
"                                                              Index Cond: (this_.alarminfoid = objectidentifier)"
"                                                  ->  Seq Scan on cw_ne ne4_  (cost=0.00..2.45 rows=1 width=174)"
"                                                        Filter: (objectidentifier = 471)"
"                                            ->  Seq Scan on cw_location location5_  (cost=0.00..2.10 rows=10 width=65)"
"                                      ->  Index Scan using cw_location_pkey on cw_location location6_  (cost=0.00..1.87 rows=1 width=65)"
"                                            Index Cond: (location5_.cw_parentlocationid = objectidentifier)"
"                                ->  Index Scan using cw_severity_pkey on cw_severity severity7_  (cost=0.00..3.87 rows=1 width=164)"
"                                      Index Cond: (location6_.cw_severityid = id)"
"                          ->  Index Scan using cw_severity_pkey on cw_severity severity8_  (cost=0.00..3.87 rows=1 width=164)"
"                                Index Cond: (location6_.cw_sublocationseverityid = id)"
"                    ->  Index Scan using cw_severity_pkey on cw_severity severity9_  (cost=0.00..8.27 rows=1 width=164)"
"                          Index Cond: (ne4_.cw_severityid = id)"
"              ->  Index Scan using cw_severity_pkey on cw_severity severity10_  (cost=0.00..8.27 rows=1 width=164)"
"                    Index Cond: (this_.severityid = id)"