Hi All,
I think this is some configuration problem but I am not able to get resultSetMapping working with NamedNativeQuery. Hibernate is not using the result set mapping provided by me. Instead it is using the default mapping and throwing exception.
Please see below all the config/code and exception details.
Regards,
Anshaj
Hibernate version:
hibernate-3.2
Mapping documents:
@Entity
@Table(name = "city")
@SecondaryTable(name="street")
@NamedNativeQuery(name = "city&street", query = "select city.city_Id as cid, city.name as cname, "
+ " street.street_id , street.name as sname, street.city_id as sid "
+ "from city city, street street where city.city_id = street.city_id", resultSetMapping = "joinMapping")
@SqlResultSetMapping(name = "joinMapping", entities = {
@EntityResult(entityClass = City.class, fields = {
@FieldResult(name = "cityID", column = "cid"),
@FieldResult(name = "name", column = "cname"), }),
@EntityResult(entityClass = Street.class, fields = {
@FieldResult(name = "streetID", column = "street_id"),
@FieldResult(name = "name", column = "sname"),
@FieldResult(name = "cityID", column = "sid") }) })
Code between sessionFactory.openSession() and session.close():
session.getNamedQuery("city&street").list();
Full stack trace of any exception that occurs:
Caused by: org.postgresql.util.PSQLException: The column name city1_1_1_ was not found in this ResultSet.
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2465)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:2306)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:103)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
at org.hibernate.loader.Loader.getRow(Loader.java:1206)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 7 more
Name and version of the database you are using:
Name: Postgresql
Version: 8.1
The generated SQL (show_sql=true):
select city.city_Id as cid, city.name as cname, street.street_id , street.name as sname, street.city_id as sid from city city, street street where city.city_id = street.city_id
Debug level Hibernate log excerpt:
|