如何解决这个问题org.hibernate.NonUniqueResultException:query没有返回唯一的结果:4

时间:2017-12-22 05:29:11

标签: spring hibernate

这是我在Dao的代码         results = [client.send(message) for client in clients] # client.send may return an error code for result in results: # process the results after all the messages were sent if result is not None: # no error means success print("client.send error:", result) # report failures, but keep going

在Hibernate中得到这样的结果     session = sessionFactory.openSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(Router.class); criteria.add(Restrictions.eq("router_id", router_id));
Router router = (Router) criteria.uniqueResult();
tx.commit(); session.close(); return router;

提前致谢

1 个答案:

答案 0 :(得分:1)

根据官方的hibernate doc,

  

当应用程序调用Query.uniqueResult()并且查询返回多个结果时抛出。

在您的情况下,返回4个结果。确保您的查询仅返回一个结果。