0 Replies Latest reply on Mar 13, 2006 12:36 PM by mazz

    eager loading and cascading - do I understand it correctly?

    mazz Master

      Can someone tell me if my understanding below is correct re: cascading.

      It seems that it would make the most sense that if you are using cascading, you should also use eager loading. If not, its concievable that you've just introduced an easy way for some client to unknowingly destroy data.

      Here's an example (note that the important part is the entity is detached when going to the client and the client is not getting or modifying the relationship's objects):

      Person has PhoneNumbers relationship that is lazy loaded but I cascade all operations.

      Client wants to change the person's nickname so it calls into a SLSB to get the Person object; the Person is loaded, detached and returned to the client. Person is loaded, but the PhoneNumbers objects are not due to the lazy fetching. Client calls Person.setNickname and then passes the Person object back to the SLSB so it can merge it. Well, at this point, the POJO has an empty set of PhoneNumbers.

      Won't the merge (when cascading) delete all of those existing PhoneNumbers related to the Person because the Person object has an empty set of PhoneNumber objects in the relationship (not because the client deleted them but because the client never asked to load them and the container never eagerly loaded them automatically).

      The client must be smart enough to know the cascading and fetching rules here - it needs to know that merging will cascade so it needs to explicitly ask to get the current set of phone numbers since it knows that with the lazy fetching it won't happen automatically.

      If that's the way cascading works, it seems that eager loading should always be enabled when cascading is enabled (unless you want to force your client developers to know about the fetching/cascading settings ahead of time).