错了
我新建了兩張表,一個bean,一個regex,分別表示檢測的實體,和對應(yīng)的正則表達式:
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)@JSONFieldprivate Integer id;@Column@JSONField@NonNullprivate String name;@Column@JSONField@NonNullprivate String type;@Column@JSONField@NonNullprivate 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;} } 復(fù)制代碼和Regex類:
@Entity @Data @NoArgsConstructor @RequiredArgsConstructor public class Regex {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)@JSONFieldprivate Integer id;@Column@JSONField@NonNullprivate String expression;@ManyToOne(cascade = {CascadeType.ALL}, optional = false)@JoinColumn(name = "beanId",referencedColumnName = "id")@JsonIgnore@JSONField(serialize = false)@NonNullprivate Bean bean;public Regex(Integer id, String expression) {this.id = id;this.expression = expression;} } 復(fù)制代碼接下來我有兩個操作,分別是create和findBeanById,代表插入和查詢操作.
現(xiàn)在的問題是如果直接查詢,我的查詢結(jié)果如下:
如果是先插入,再查詢,我的查詢結(jié)果如下:
問題是:先插入在查找,和直接查找的結(jié)果不一樣.....
轉(zhuǎn)載于:https://juejin.im/post/5cf79f01e51d454fa33b1875
總結(jié)
- 上一篇: Python多线程原理与实现
- 下一篇: Git Gitlab 使用指南之Tor