繁体   English   中英

HIbernate 忽略从 OnetoMany 字段获取数据

[英]HIbernate ignore fetching data from OnetoMany field

我想忽略实体中的@OnetoMany字段。 获取数据需要获取实际字段但不想触发对依赖表的查询。 但是从父表中删除数据需要从依赖表中删除

我试过忽略但删除也被忽略的@Transient 当我调用父实体时,还有其他选项可以告诉 JPA 不要从子表中获取数据吗?

@Entity
Table(name = "User")
public class UserEntity implements Serializable {
    @Id
    @Column(name = "id")
    private int id;

    @Column(name = "SERIAL", unique = true, nullable = false)
    private String serial;

    @OneToMany(mappedBy = "serialBySerialId", cascade = CascadeType.ALL)
    private Set<UserActionEntity> userActionsById;

}

@Table(name = "user_action")
public class UserActionEntity implements Serializable {

    @Id
    @Column(name = "id")
    private int id;

    @Column(name = "action")
    private String action;

    @ManyToOne
    @JoinColumn(name = "USER_ID", referencedColumnName = "ID", nullable = false)
    private UserEntity userByUserId;



如果您不想触发对依赖表的查询,您可以在 UserActionEntity 属性上使用 (fetch = FetchType.LAZY)。

 @OneToMany(mappedBy = "serialBySerialId", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
        private Set<UserActionEntity> userActionsById;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM