我有一个Java REST服务,它提供一个服务,将JSON返回给客户端(使用Tomcat和Jersey)。我一直在寻找这个问题好几天了,我真的不明白,因为服务器提供的另一个呼叫几乎是相同的,它的工作正常.... REST服务:
//working
@GET
@Path("/listAll")
@Produces({ MediaType.APPLICATION_JSON })
public List<Route> getAllRoutes() {
EntityManager em = getEntityManager();
Query q = em.createQuery("select r from Route r ");
@SuppressWarnings("unchecked")
List<Route> routeList = q.getResultList();
em.close();
return routeList;
}
MySQL表'waypoint'包含3列:ID(BIGINT),COORDINATE(VARCHAR),ROUTEID(BIGINT)。如果这很重要,那么该项目将在Liferay上运行....就像我说的那样,我已经不再有任何想法了:/奇怪的是“/ listAll”调用工作正常,但“/ getPoints”返回500和日志只是:
connection: 2015-01-13 18:10:47.715--ServerSession(27137311)--Thread(Thread[http-bio-8080-exec- 21,5,main])--client acquired: 18571860
[EL Finer]: transaction: 2015-01-13 18:10:47.715--ClientSession(18571860)--Thread(Thread[http-bio-8080-exec-21,5,main])--acquire unit of work: 32602042
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--begin unit of work flush
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--end unit of work flush
[EL Finest]: query: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--Execute query ReadAllQuery(referenceClass=WayPoint sql="SELECT ID, ROUTEID, COORDINATE FROM WAYPOINT")
[EL Finest]: connection: 2015-01-13 18:10:47.715--ServerSession(27137311)--Connection(21934325)--Thread(Thread[http-bio-8080-exec-21,5,main])--Connection acquired from connection pool [default].
[EL Finest]: connection: 2015-01-13 18:10:47.715--ServerSession(27137311)--Connection(21934325)--Thread(Thread[http-bio-8080-exec-21,5,main])--Connection released to connection pool [default].
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--begin unit of work commit
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--end unit of work commit
[EL Finer]: transaction: 2015-01-13 18:10:47.715--UnitOfWork(32602042)--Thread(Thread[http-bio-8080-exec-21,5,main])--release unit of work
谢谢你们/女孩们;)
问候
答案 0 :(得分:1)
检查您的getter中的长 - >长转换为RouteId。如果RouteId为null,则在调用getter时会有一个隐式方法调用从Long转换为long(通常在序列化到json期间发生)。如果RouteId为null,那么该方法调用将在框架代码深处的某处产生NullPointerException,当它冒泡到容器时将实现500错误。