4

Hibernate 3.3.1 GAとを使用してプロジェクトを設定していPostgreSQL 8.3ます。最初のテーブルであるデータベースを作成し、そこに1つの行を追加して、Hibernateを構成しました。

ただし、最も単純なクエリでも次のようになります。

Criteria criteria = session.createCriteria(Place.class);
List result = criteria.list();

実行できませんでした(データベースに1つのレコードがありますが、空のリストが返されます)。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:エンティティcom.example.data.Placeの静的選択:place0_.IDをID0_0_、place0_.NAMEをNAME0_0_、place0_.LATITUDEをLATITUDE0_0_、place0_.LONGITUDEとして選択PLACEplace0_からLONGITUDE0_0_としてplace0_.ID=?

psql内のデータベースに対して再度実行すると、機能します(これは、Hibernateが適切なSQLを生成したことを意味します)。

以下はHibernateの構成です。

<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は無駄ではありませんでした。何かアイデア、コミュニティ?

4

1 に答える 1

3

デバッガーをHibernateコードに適用した後、修正されました!

質問のテキストには表示されませんが、問題は、メソッドにPlace渡されるのが、構成XMLファイルで指定されたではcreateCriteria()なく別のパッケージからのものであるということです。com/example/data

Hibernateはを呼び出しClass.isAssignableFrom()、falseが返された場合はサイレントに終了し、接続を切断します。この問題について、Hibernate開発者向けのチケットを開きます。

于 2008-09-20T14:13:04.373 に答える