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=993896https://forum.hibernate.org/viewtopic.php?t=981153http://www.javakb.com/Uwe/Forum.aspx/java-databases/3070/PgSQL-Exception-column-name-not-foundIs this a bug ? Should I report it ?
Thanks.