How can I update a collection type relationship with mappedBy in Hibernate?
I have two related objects, say
@Entity
public class Book {
@ManyToOne
Shelf shelf;
}
@Entity
public class Shelf {
@OneToMany(mappedBy="shelf")
Set<Book> books;
}
If I take an empty shelf (no books), create and save a new book on the shelf and then take that shelf again, its book collection is empty. When I run it with debug log I see that Hibernate is not looking for the shelf a second time, it just returns it from the session cache where it does not know that the book collection has been updated.
How can I get rid of the effect and get an updated shelf state?
Thank you,
Artem.
+1
a source to share