I have the following class
@Entity(name = "table")
@Table(name = "table")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SomeClass {
@Id
long id;
@OneToMany(mappedBy = "someObject")
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private List<AnotherClass> anotherObjects;
}
And another class:
public class AnotherClass{
@Id
long id;
@ManyToOne
@JoinColumn(name = "some_coulmn")
SomeClass someObject;
}
The scenario is that when I create an object from type AnotherClass
assigning it a certain someClass
object and then retrieve that someClass
object, I do not see the newly created object (unless I flush the cache and restart).
Is there anything I can do to update the collection representing the relation between two entities whenever a new entity is added to that relation?
Note: I am using hibernate 5.3 in Spring boot 2.1.8 project.