我无法将查询结果映射到POJO。
JPA执行查询ok(它在日志中跟踪)但在映射过程中抛出NPE。
有什么问题?
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)
执行代码:
List<TiendaTO> tiendas = entityManager.createNamedQuery("TiendaResources.tiendas_del_usuario", TiendaTO.class).setParameter(1, user.getId()).getResultList();
的元数据:
<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="TiendaTOMapping">
<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
谢谢!
答案 0 :(得分:0)
是 com.silyan.meyem.view.visor.tienda.TiendaTO 映射的课程吗?如果没有,那么您将遇到此问题:https://bugs.eclipse.org/bugs/show_bug.cgi?id=288957
但另一方面“实体 -result 实体 -class”,实体是有意义的,当然一些实现也可以支持其他类