I can't map query result to POJO.
JPA executes query ok (it trace in logs) but in mapping process throws a NPE.
What is wrong?
NPE:
java.lang.NullPointerException
at org.eclipse.persistence.queries.EntityResult.getValueFromRecord(EntityResult.java:147)
at org.eclipse.persistence.queries.ResultSetMappingQuery.buildObjectsFromRecords(ResultSetMappingQuery.java:165)
at org.eclipse.persistence.queries.ResultSetMappingQuery.executeDatabaseQuery(ResultSetMappingQuery.java:215)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:589)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2857)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1181)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:453)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:681)
at com.silyan.meyem.view.visor.tienda.TiendaResources.delusuario(TiendaResources.java:284)
execution code:
List<TiendaTO> tiendas = entityManager.createNamedQuery("TiendaResources.tiendas_del_usuario", TiendaTO.class).setParameter(1, user.getId()).getResultList();
metadata:
<named-native-query name="TiendaResources.tiendas_del_usuario" result-set-mapping="TiendaTOMapping">
<query>
select
tienda.id as id,
tienda.nombre as nombre,
tienda.idporcliente as idporcliente,
tienda.cliente_id as clienteid,
ST_X(direccion.geolocalizacion) as x,
ST_Y(direccion.geolocalizacion) as y
from
user_tienda,
tienda,
direccion
where
user_tienda.user_id = ? and
tienda.id = user_tienda.tienda_id and
direccion.id = tienda.direccion_id
</query>
</named-native-query>
<sql-result-set-mapping name="Tien开发者_高级运维daTOMapping">
<entity-result entity-class="com.silyan.meyem.view.visor.tienda.TiendaTO" >
<field-result name="id" column="id"/>
<field-result name="idPorCliente" column="idporcliente"/>
<field-result name="nombre" column="nombre"/>
<field-result name="x" column="x"/>
<field-result name="y" column="y"/>
</entity-result>
</sql-result-set-mapping>
Plataform: Glassfish 3.0.1 - eclipselink 2.0.1.v20100213-r6600
Thanks!
Is com.silyan.meyem.view.visor.tienda.TiendaTO mapped class? If not, then you are facing this problem: https://bugs.eclipse.org/bugs/show_bug.cgi?id=288957
But on the other hand "entity-result entity-class", it kind of makes sense that entity is expected, of course some implementations can support also other classes.
精彩评论