jps 实体关联 OneToMany 双向关联 (ManyToOne)
程序员文章站
2022-03-02 15:25:42
...
jps 实体关联 OneToMany 双向关联 (ManyToOne) 例子(可以对一的 一方操作)
多的一方
/**
* @Author: sunyanhui
* @Date: 2021/3/2 14:25
*/
@Entity
@Table(name = "shop_pos_screen_setting")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ShopPOSScreenSettingEntity extends BaseBusinessEntity {
@Column(name = "shop_id")
private Long shopId;
@Column(name = "switching_time")
private Integer switchingTime;
@OneToMany(mappedBy = "shopPOSScreenSettingEntity", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@OrderBy("sort")
private List<ShopPOSScreenItemEntity> shopPOSScreenItemEntityList;
public ShopPOSScreenSettingEntity( Long shopId) {
this.shopId = shopId;
}
}
一的一方
/**
* @Author: sunyanhui
* @Date: 2021/3/2 17:33
*/
@Entity
@Table(name = "shop_pos_screen_item")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ShopPOSScreenItemEntity {
@Id
@Column(name = "id")
private Long id;
@Column(name = "shop_id")
private Long shopId;
@Column(name = "type")
private Type type;
@Column(name = "url")
private String url;
@Column(name = "sort")
private Integer sort;
@ManyToOne
@JoinColumn(name = "shop_id", referencedColumnName = "shop_id", insertable = false, updatable = false)
@NotFound(action = NotFoundAction.IGNORE)
@JsonIgnore
private ShopPOSScreenSettingEntity shopPOSScreenSettingEntity;
public ShopPOSScreenItemEntity(Long id, Long shopId, Type type, String url, Integer sort) {
this.id = id;
this.shopId = shopId;
this.type = type;
this.url = url;
this.sort = sort;
}
/*0:图片, 1:视频*/
public enum Type {
PICTURE,
VIDEO
}
}
下一篇: 关于netty的疑惑
推荐阅读
-
Hibernate基础之九:多对多,单/双向关联 @ManyToOne @OneToMany
-
@Lazy和@Proxy,关联关系@OneToOne,@OneToMany,@ManyToOne,@ManyToMany
-
JPA中关联关系(OneToOne、OneToMany、ManyToMany,ManyToOne)映射代码片段
-
JPA中关联关系(OneToOne、OneToMany、ManyToMany,ManyToOne)映射代码片段
-
Hiberante(五) OneToMany_xml 双向关联
-
oneToMany,ManyToOne双向关联
-
jps 实体关联 OneToMany 双向关联 (ManyToOne)
-
JPA OneToMany双向关联
-
Hibernate——ManyToOne双向关联