错了

我新建了两张表,一个bean,一个regex,分别表示检测的实体,和对应的正则表达式:

bean(id,name,type)

regex(id,expression,bean_id)

regex表中的bean_id是外键.

接下来我在java代码中新建了两个实体类:

Bean类

@Entity
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
public class Bean {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JSONField
    private Integer id;

    @Column
    @JSONField
    @NonNull
    private String name;

    @Column
    @JSONField
    @NonNull
    private String type;

    @Column
    @JSONField
    @NonNull
    private Integer uuid;

    @OneToMany(mappedBy = "bean",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    private List<Regex> regexList;


    public Bean(Integer id, @NonNull String name, @NonNull String type) {
        if (name == null) {
            throw new NullPointerException("name is marked @NonNull but is null");
        } else if (type == null) {
            throw new NullPointerException("type is marked @NonNull but is null");
        }
        this.id=id;
        this.name = name;
        this.type = type;
    }
}
复制代码

和Regex类:

@Entity
@Data
@NoArgsConstructor
@RequiredArgsConstructor
public class Regex {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JSONField
    private Integer id;

    @Column
    @JSONField
    @NonNull
    private String expression;

    @ManyToOne(cascade = {CascadeType.ALL}, optional = false)
    @JoinColumn(name = "beanId",referencedColumnName = "id")
    @JsonIgnore
    @JSONField(serialize = false)
    @NonNull
    private Bean bean;

    public Regex(Integer id, String expression) {
        this.id = id;
        this.expression = expression;
    }
}
复制代码

接下来我有两个操作,分别是create和findBeanById,代表插入和查询操作.

现在的问题是如果直接查询,我的查询结果如下:

如果是先插入,再查询,我的查询结果如下:

问题是:先插入在查找,和直接查找的结果不一样.....

转载于:https://juejin.im/post/5cf79f01e51d454fa33b1875

猜你喜欢

转载自blog.csdn.net/weixin_34257076/article/details/91467397