3 Replies Latest reply on Jan 13, 2011 10:20 AM by Adam Warski

    Obtaining null when trying to get a related entity mapped as @ManyToOne

    André Almeida Newbie

      Hi everyone!


              I'm having a hard time doing a query in my audited entities on  jboss.envers-1.2.2.GA-hibernate-3.3.


              I have two entities, workers and teams. Each worker can be   associated  with just one team. In the entity worker I have a @ManyToOne    unidirectional relationship to the entity team, like this:


           @ManyToOne(fetch = FetchType.EAGER)
           @JoinColumn(name = "ID_TEAM", nullable = false)
           @ForeignKey(name = "RN_TEAM_FK1")
           @Cascade( { CascadeType.PERSIST, CascadeType.MERGE })
           private Team responsibleTeam;


             When I try to get the responsible team associated with the revision of worker, I'm obtaing null. Here is the code:


           AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(Workers.class, revision);

           Worker workerRevision = (Worker) query.getSingleResult();

           String workerName = workerRevision.getName(); // This operation is returning the right name
           Team team = workerRevision.getResponsibleTeam(); // This operation is returning null



             Is that the correct behavior?


             If I am doing something wrong, how could I retrieve the "responsibleTeam" associated with the revision of worker?


      Thanks for your help.