1 Reply Latest reply on May 5, 2009 4:35 PM by ztiringer

    Strange query problem

    charlscross

      Hi!!
      I have this class:


      public class Program implements java.io.Serializable {
      
           private long programId;
           private Course course;
        
               //With Course mapped this way:
               @ManyToOne(fetch = FetchType.LAZY)
           @JoinColumn(name = "CURS_ID", nullable = false)
           @NotNull
           public CursEscolar getCursEscolar()....etc
      
      
      }
      


      If I do this query:


      List<Program> programs = entityManager.createQuery("From Program p ").getResultList;
      



      I retrieve a list of programs and the course the program belongs OK.


      But if I do this other query:


      List<Program> programs = entityManager.createQuery("From Program p where p.programId= :progId ")
      .setParameter("progId", pro.getProgramId())
      .getResultList();
      
      
      


      I retrieve the Course with id=0, and the fields null. The only difference is the condition:


      p.programId= :progId
      



      Why happens this??