【问题标题】:Unable to find Entity not found exception when using one-to-many bidirectional使用一对多双向时找不到实体未找到异常
【发布时间】:2020-02-21 06:10:42
【问题描述】:

使用邮递员发布数据或运行程序时,遇到以下错误:

无法找到 id 为 1 的 com.example.entity.Product;嵌套异常是 javax.persistence.EntityNotFoundException: Unable to find com.example.entity.Product with id 1

下面是父类:

@Entity
public class Customer {
    @Id
    @GeneratedValue
    private Integer cust_Id;
    private String cust_name;
    private String city;

    @OneToMany(mappedBy = "customer")
    private List<Product> products;
}

Child class:
@Entity
public class Product {
    @Id
    private Integer pid;
    private String pname;

    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "fk_cust_id")
    private Customer customer;
}

【问题讨论】:

  • 你用的是什么休眠版本?
  • Spring boot with data-jpa, Spring boot-2.0.1.RELEASE

标签: spring hibernate spring-boot spring-data


【解决方案1】:

@NotFound(action=NotFoundAction.IGNORE) 导致 @ManyToOne(fetch = FetchType.LAZY) 字段的 EAGER 加载。 Refer here

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多