Hello,
We are using hibernate 3.X thru JPA.
So I have an entity and it has many relationships thru collections to many other entities. Our code generator marked all these collections with "CascadeType.All" and "fetch=FetchType.LAZY".
When we persist entity A by calling EntityManager.Persist(), i see that Hibernate is hitting the DB to load the collections on the A - many many select statements. These collections are lazy, but they are all getting loaded at the time of the persist! Then when it pulls in those collections, it goes on and pulls in the collections on those associated entities! Pretty soon our whole DB is in memory :)
Reading up on CascadeType.All, I would think that it would cause the entities in the annotated collection to be persisted when the A is persisted, fine. By why would it try to load up the collection by hitting the DB with a select statement? Shouldn't the graph traversal stop when it hits an uninstantiated lazy-load collection?
Also, if we have an entity A that has a collection of entity B's, is CascadeType.All/CascadeType.Persist the only way to say "when you persist the A, persist the transient B's too"? Or can we expect hibernate to traverse the graph of objects (at least the instantiated ones), looking for associated entities to persist?
Thanks,
JP
|