我将SpringJPA与Hibernate一起使用。 我有一个缓存的bList。 当我使用CrudRepository的save方法创建一个新的B实体(实体B有一个对A的引用)时,bList保持为空。当我重新启动应用程序时,使用新元素更新bList。 如何在创建B实体后自动更新缓存的bList?
@Entity
@Table(name = "A")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class A extends AbstractAuditingEntity implements Serializable {
...
@OneToMany(mappedBy = "a",fetch = FetchType.EAGER)
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Set<B> bList = new HashSet<>();
...
@Entity
@Table(name = "B")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class B extends AbstractAuditingEntity implements Serializable {
...
@ManyToOne
private A a;