【发布时间】:2013-03-29 04:05:36
【问题描述】:
我正在为我的网络服务使用休眠。
我可以列出所有记录,但不能只列出一条。
表格包含:
ID (VARCHAR) VALUE(BIT)
celiac 1
rate 1
suggestions 0
显示的错误是:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.pfc.restaurante.models.Device#id="xxxxxx"]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
以及主要代码:
@JsonAutoDetect
@Entity
@Table(name = "SETTINGS")
public class Settings implements Serializable{
@Id
@Column(name="ID")
private String id;
@Column(name="VALUE", nullable=false)
private boolean value;
(...)
}
//////////////////7
@Controller
@RequestMapping("/settingsService")
public class SettingsServiceController {
@Autowired
SettingsService settingsService;
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public @ResponseBody Settings find(@PathVariable("id") String id){
return settingsService.find(id);
}
(...)
}
我已经阅读过,这可能是因为 DB 与我的实体不一致(一些 nullable = true 时不应该),但我已经检查过了,没有这样的事情。
有人可以帮我吗?
提前致谢!
【问题讨论】:
-
这是你的
Settings类,例外是指Device类。向我们展示真实的日志(带有真实 ID,而不是xxxxx)、设备表和设备类。 -
对不起,我的错。然而,设备和设置的错误是相同的,并且 xxxx 是一个真实的测试 ID :)。感谢 Antonio,上述解决方案已成功。