0

我正在为我的网络服务使用休眠。

我可以列出所有记录,但无法仅列出一条。

该表包含:

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);
    }
          (...)
}

我已经阅读过,这可能是因为数据库与我的实体不一致(一些 nullable = true 时不应该),但我已经检查过了,没有这样的事情。

有人可以帮帮我吗?

提前致谢!

4

1 回答 1

6

您的错误涉及一个名为“设备”的实体,但您的代码显示了一个实体“设置”。他们是一样的吗?

我仅在 2 种情况下看到此错误:

  1. 数据库中不存在主要实体,使用 Session.load()。使用 Session.get() 并检查 null 。

  2. 破裂的关系。考虑一下:EntityA 拥有与 EntityB 的关系。EntityB 被删除,而 EntityA 中的 FK 保持不变。因此,每当 HB 尝试加载链接 AB 时,就会发生错误。这可能在运行正常搜索时甚至在保存/刷新 EntityA 时发生(HB 也需要刷新链接)。

于 2013-04-07T02:40:05.613 回答