2 Replies Latest reply on Jun 1, 2010 8:42 AM by Rob Pridham

    ManyToOne & lazy initialization

    Rob Pridham Newbie

      Hi,

       

      I'm fairly sure this is a simple task, but I can't find much about it, so please bear with me.

       

      I've got an audited entity called Category. When something happens to one of them, on update or persist, I want to create change reports. Therefore I pull the last copy up using AuditReader and compare its properties. For the simple properties, this works fine.

       

      However Category also has a 'parent' property, another Category. getParentCategory() is annotated with @ManyToOne.

       

      When I try to pull this from my Category object, I get a lazy initialization handler, and thus getParentCategory().getWhatever() returns null. I see it has the parent's correct ID in the handler's details, which would be enough for my purposes, but I can't get at that.

       

      I don't want to merge the old object back in, only examine it. I've tried annotating getParentCategory() with:

       

      @ManyToOne(optional = true, fetch=FetchType.EAGER)

       

      but it has no effect.

       

      What can I do?

       

      Cheers,

       

      Rob