최대 절전 모드 3:PostgreSQL 데이터베이스를 쿼리할 수 없습니다.
-
01-07-2019 - |
문제
나는 다음을 사용하여 프로젝트를 설정하고 있습니다. Hibernate 3.3.1 GA
그리고 PostgreSQL 8.3
.나는 방금 첫 번째 테이블인 데이터베이스를 생성하고 거기에 한 행을 추가했으며 이제 Hibernate를 구성했습니다.
그러나 가장 간단한 쿼리라도 다음과 같습니다.
Criteria criteria = session.createCriteria(Place.class);
List result = criteria.list();
실행할 수 없습니다(데이터베이스에 레코드가 하나 있어도 빈 목록이 반환됨).PostgreSQL 로그를 살펴보며 다음을 확인했습니다.
2008-09-17 22:52:59 CEST LOG: connection received: host=192.168.175.1 port=2670
2008-09-17 22:52:59 CEST LOG: connection authorized: user=... database=...
2008-09-17 22:53:00 CEST LOG: execute <unnamed>: SHOW TRANSACTION ISOLATION LEVEL
2008-09-17 22:53:02 CEST LOG: could not receive data from client: Connection reset by peer
2008-09-17 22:53:02 CEST LOG: unexpected EOF on client connection
2008-09-17 22:53:02 CEST LOG: disconnection: session time: 0:00:03.011 user=... database=... host=192.168.175.1 port=2670
나는 동일한 데이터를 가져오기 위해 일반 JDBC를 사용하여 간단한 프로그램을 작성했고 제대로 작동했습니다.이 경우 PostgreSQL 로그는 다음과 같습니다(비교용).
2008-09-17 22:52:24 CEST LOG: connection received: host=192.168.175.1 port=2668
2008-09-17 22:52:24 CEST LOG: connection authorized: user=... database=...
2008-09-17 22:52:25 CEST LOG: execute <unnamed>: SELECT * from PLACE
2008-09-17 22:52:25 CEST LOG: disconnection: session time: 0:00:00.456 user=... database=... host=192.168.175.1 port=2668
Hibernate 디버그 로그에는 오류가 표시되지 않습니다.로그에 나열된 쿼리를 수행하면 다음과 같습니다.
15:17:01,859 DEBUG org.hibernate.loader.entity.EntityLoader: Static select for entity com.example.data.Place: select place0_.ID as ID0_0_, place0_.NAME as NAME0_0_, place0_.LATITUDE as LATITUDE0_0_, place0_.LONGITUDE as LONGITUDE0_0_ from PLACE place0_ where place0_.ID=?
그리고 psql에 있는 데이터베이스를 다시 실행하면 작동합니다(이것은 Hibernate가 적절한 SQL을 생성했음을 의미합니다).
다음은 최대 절전 모드 구성입니다.
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.175.128:5433/...</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">...</property>
<property name="hibernate.connection.password">...</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.use_outer_join">true</property>
<mapping resource="com/example/data/Place.hbm.xml"/>
</session-factory>
</hibernate-configuration>
...그리고 매핑 파일:
<hibernate-mapping package="com.example.data">
<class name="com.example.data.Place" table="PLACE">
<id column="ID" name="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property column="NAME" name="name" not-null="true" type="java.lang.String">
<meta attribute="use-in-tostring">true</meta>
</property>
<property column="LATITUDE" name="latitude" not-null="true" type="java.lang.Float">
<meta attribute="use-in-tostring">true</meta>
</property>
<property column="LONGITUDE" name="longitude" not-null="true" type="java.lang.Float">
<meta attribute="use-in-tostring">true</meta>
</property>
</class>
</hibernate-mapping>
인터넷 검색 unexpected EOF
로그 항목이 소용이 없었습니다.어떤 아이디어나 커뮤니티가 있나요?
해결책
Hibernate 코드에 디버거를 적용한 후에는 수정되었습니다!
질문 텍스트에는 표시되지 않지만 문제는 Place
에 전달 createCriteria()
메소드가 다른 패키지에 있습니다. com/example/data
, 구성 XML 파일에 지정됩니다.
최대 절전 모드 호출 Class.isAssignableFrom()
, false가 반환되면 자동으로 종료되어 연결이 끊어집니다.나는 이 문제에 관해 Hibernate 개발자들을 위한 티켓을 열 것입니다.