I have Cluster/Shelf relation(parent/child) like this.
Cluster.java
----------
Code:
@OneToMany(cascade = { CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE }, mappedBy = "cluster")
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public List<ShelfDBObj> getShelves() {
return shelves;
}
Between a start and commit transaction for Cluster/Shelf
Code:
Cluster exists in database
..starttrx
ClusterDBObj cluster = //query cluster
ShelfDBObj shelf = new ShelfDBObj();
cluster.addShelf(shelf);
dao.persist(shelf); [b](Is Needed to save in database)[/b]
commit trx
I have Shelf/Card relation(parent/child) like this.
Shelf.java
---------
Code:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "shelf")
public List<CardDBObj> getCards() {
return cards;
}
Between a start and commit transaction for Shelf/Card
Code:
Shelf exists in database
..starttrx
ShelfDBObj shelf = //query shelf
CardDBObj card = new CardDBObj();
shelf.addCard(card);
commit trx // dao.persist(card) is not needed
At the point of commit transaction, the first trx needs an explicit save and the second trx does not need an explicit save. Why? What are the differences in the Cascade types. Please explain.