Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql &引用;org.hibernate.ObjectNotFoundException:不存在具有给定标识符的行;但它确实存在_Mysql_Spring_Hibernate - Fatal编程技术网

Mysql &引用;org.hibernate.ObjectNotFoundException:不存在具有给定标识符的行;但它确实存在

Mysql &引用;org.hibernate.ObjectNotFoundException:不存在具有给定标识符的行;但它确实存在,mysql,spring,hibernate,Mysql,Spring,Hibernate,我正在为我的web服务使用hibernate 我可以列出所有的记录,但不能只得到一条 该表包括: ID (VARCHAR) VALUE(BIT) celiac 1 rate 1 suggestions 0 显示的错误是: org.springframework.web.util.N

我正在为我的web服务使用hibernate

我可以列出所有的记录,但不能只得到一条

该表包括:

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与我的实体不一致(不应该的时候,有些null=true),但我已经检查过了,没有这样的事情

有人能帮我一下吗


提前谢谢

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

我只在两种情况下见过这个错误:

  • 数据库中不存在主实体,使用了Session.load()。使用Session.get()并检查是否为null

  • 破裂的关系。想想看:EntityA和EntityB有关系。EntityB被删除,而EntityA中的FK保持不变。因此,每当HB尝试加载链接A-B时,就会发生错误。这可能发生在运行正常搜索时,甚至在保存/刷新EntityA时(HB也需要刷新链接)


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

    我只在两种情况下见过这个错误:

  • 数据库中不存在主实体,使用了Session.load()。使用Session.get()并检查是否为null

  • 破裂的关系。想想看:EntityA和EntityB有关系。EntityB被删除,而EntityA中的FK保持不变。因此,每当HB尝试加载链接A-B时,就会发生错误。这可能发生在运行正常搜索时,甚至在保存/刷新EntityA时(HB也需要刷新链接)


  • 这是您的
    设置
    类,异常指的是
    设备
    类。显示真实日志(带有真实ID,而不是
    xxxxx
    )、设备表和设备类。很抱歉,我的错误。然而,设备和设置的错误是相同的,xxxx是一个真实的测试ID:)。由于Antonio,上述解决方案已成功。这是您的
    设置
    类,异常指的是
    设备
    类。显示真实日志(带有真实ID,而不是
    xxxxx
    )、设备表和设备类。很抱歉,我的错误。然而,设备和设置的错误是相同的,xxxx是一个真实的测试ID:)。多亏了安东尼奥,上面的解决方案是成功的。事实上,他们也给了我同样的错误。对不起,我忘了更改错误。无论如何,谢谢你!第一个解决方案是正确的。我正在使用session.load()。我刚刚为session.get()更改了它,现在它工作正常。事实上,他们给了我相同的错误。对不起,我忘了更改错误。无论如何,谢谢你!第一个解决方案是正确的。我正在使用session.load()。我刚刚为session.get()更改了它,现在它可以正常工作了。