0 Replies Latest reply on Jul 31, 2005 8:10 AM by Joachim Van der Auwera

    Collection mapping woes

    Joachim Van der Auwera Expert

      Referencing [url]http://www.jboss.org/index.html?module=bb&op=viewtopic&t=66927[url]

      triathlon98 wrote :

      I have some problems with the collection caching support.
      This is working (and doing good work) most of the time, but I sometimes get a NPE in org.hibernate.engine.CollectionLoadContext.addCollectionToCache(306).

      Are there any workarounds for this issue (aside from disabling the cache)?

      Also, how does the invalidation of the collection cache work? Should this be handled manually, or does this occur automatically?

      epbernard wrote :

      Sometimes is a bit vague to find the problem. The cache is working.
      The invalidation is done by the persistence engine and/or your clache configuration automatically.

      triathlon98 reply :

      The behaviour I am getting is deterministic. That is, I have a test which fails all the time. Unfortately it is a bit difficult to reduce/transfer as it requires our entire application and specific data (quite a lot of it). In the general case, it is working. However, I see that when this problem occurs, a lot of objects are being loaded (more then I expected, but that is another matter).

      I have this in some code which returns a value object (does not use detached objects for compatibily with existing code). This does a entitymanager.flush and then builds the value object. The flush is needed to get the current value for fields calculated in @PreUpdate methods. In the transaction, this is going just fine for many objects, then suddenly it throws a hibernate exception about trying to use a not-initialized collection.
      As the PreUpdate side-effects are not yet saved at the moment (beta 1), I tried to remove the flush, in which case I get a NPE in org.hibernate.engine.CollectionLoadContext.addCollectionToCache(306) when trying to get the collection for one of the fields in the entity. As this line seems to be related to version handling of the linked objects, I tried several versioning configurations (none, timestamp and int version column), but this had no effect. The only solution I could find after 12h of hunting was to switch off the collection cache. Then it works.

      I know haven't got a simple reproducable testcase I can send over, but having a NPE does not seem normal.

      I hope this helps to pin down the problem.
      Joachim