-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: PSQLException with native Postgis Query
PostPosted: Tue Jun 21, 2011 8:33 am 
Newbie

Joined: Tue Jun 21, 2011 6:22 am
Posts: 1
Hello,
I am new to the hibernate's world, and I wanted to take advantage of this short note to congratulate the authors, I'm really impressed with the quality of your work ...

I get a PSQLException when I try to run a native query:

Code:
@NamedNativeQuery(
    name="Flow.getWithin",
    query="SELECT "
        + "id, id_user, latitude,longitude, title, isocountry, created_at, is_adult_reserved, is_moderate, is_public, reach, date_end, date_start "
        + "FROM ws_flow "
        + "WHERE "
        + "ST_DWithin(geo_location, ST_GeographyFromText('SRID=4326;POINT(' || :lat || ' ' || :lon || ')'), :reach) "
        + "AND date_end > now() "
        + "AND is_active=true "
        + "AND isocountry = :country ",
    resultSetMapping="getWithinMapping"
)
@SqlResultSetMapping(name="getWithinMapping", entities={
    @EntityResult( entityClass=com.lestanukis.streetama.data.entity.Flow.class, fields = {
        @FieldResult(name="id", column="id"),
        @FieldResult(name="idUser", column="id_user"),
        @FieldResult(name="latitude", column="latitude"),
        @FieldResult(name="longitude", column="longitude"),
        @FieldResult(name="title", column="title"),
        @FieldResult(name="country", column="isocountry"),
        @FieldResult(name="createdAt", column="created_at"),
        @FieldResult(name="isAdultReserved", column="is_adult_reserved"),
        @FieldResult(name="isModerate", column="is_moderate"),
        @FieldResult(name="isPublic", column="is_public"),
        @FieldResult(name="reach", column="reach"),
        @FieldResult(name="dateEnd", column="date_end"),
        @FieldResult(name="dateStart", column="date_start")
    })
})


Here is the Exception:

Quote:
Caused by: org.postgresql.util.PSQLException: The column name city183_0_ was not found in this ResultSet.
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2562)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:2405)
at com.sun.gjc.spi.base.ResultSetWrapper.getString(ResultSetWrapper.java:408)
...


The city column is excluded from the getWithinMapping SqlResultSetMapping...

And the code in my DAO that execute the query:

Code:
Query q = em.createNamedQuery("Flow.getWithin");
q.setParameter("lat", lat);
q.setParameter("lon", lon);
q.setParameter("reach", reach);
q.setParameter("country", country);


I feel that this bug is a bit random because I just made this little refactoring, and I have no error:

Code:
String s = "SELECT * "
+ "FROM ws_flow "
+ "WHERE "
+ "ST_DWithin(geo_location, ST_GeographyFromText('SRID=4326;POINT(' || :lat || ' ' || :lon || ')'), :reach) "
+ "AND date_end > now() "
+ "AND is_active=true "
+ "AND isocountry = :country ";

Query q =em.createNativeQuery(s, Flow.class);
q.setParameter("lat", lat);
q.setParameter("lon", lon);
q.setParameter("reach", reach);
q.setParameter("country", country);

List<Flow> f = q.getResultList();


Could'nt be a cache problem ?

I found some topic with the same problem, but without clear solution...

https://forum.hibernate.org/viewtopic.php?t=993896
https://forum.hibernate.org/viewtopic.php?t=981153
http://www.javakb.com/Uwe/Forum.aspx/java-databases/3070/PgSQL-Exception-column-name-not-found

Is this a bug ? Should I report it ?

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.