Hibernate 3: unable to query PostgreSQL database

I am creating a project using Hibernate 3.3.1 GAand PostgreSQL 8.3. I just created a database, the first table, added one row there and now I am setting up Hibernate.

However, even the simplest request:

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

failed to execute (an empty list is returned, although there is one record in the database). I looked through the PostgreSQL logs to see:

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

I wrote a simple program using simple JDBC to retrieve the same data, and it worked. The PostgreSQL logs in this case look like this (for comparison):

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  

The Hibernate debug log does not indicate any errors. If I take the request specified in the logs:

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:

<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>

googling unexpected EOF . , ?

+3
1

Hibernate !

, , Place, createCriteria(), , com/example/data, XML.

Hibernate Class.isAssignableFrom(), false , , . Hibernate .

+2

Source: https://habr.com/ru/post/1697258/


All Articles