title: Hibernate criteria for many to one, ignore a column when retrieving data?
body: <p>I have 3 Entities.<br/></p>
  
  <ol>
  <li>Employee.</li>
  <li>Ticket.</li>
  <li>Comment.</li>
  </ol>
  
  <p>Each of them has one-to-many relationships with each other. I need to retrieve a record of single <strong>Ticket</strong>. But when I am getting the data along with it comes the data of the employee mapped to it. In the employee data that is coming, <strong>I don't want the password field data to be retrieved along with the other fields. SO WHAT MUST BE THE CRITERIA QUERY FOR THIS</strong></p>
  
  <p><strong>EMPLOYEE CLASS</strong></p>
  
  <pre><code>@Entity
  @NamedQuery(name = "getUserByEmail", query = "from Employee where emaillAddress = :emailAddress")
  public class Employee implements Serializable {
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      @JsonIgnore
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "employee_id", updatable = false)
      private int empId;
  
      @JsonIgnore
      @Column(name ="emp_code" ,unique = true, nullable = false)
      private long employeeCode;
  
      @Column(name = "full_name", nullable = false)
      private String fullName;
  
      @JsonIgnore
      @Column(name = "email_address", nullable = false, unique = true)
      private String emaillAddress;
  
      @JsonIgnore
      @Column(name = "password", nullable = false)
      private String password;
  
  
      @Column(name = "employee_role", nullable = false)
      private int role;
  
      @JsonIgnore
      @OneToMany(mappedBy = "owner", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
      private Collection&lt;Ticket&gt; tickets = new ArrayList&lt;&gt;();
  
      public Employee() {
          this.fullName = "";
          this.password = "";
          this.emaillAddress = "";
          this.role = 2;
      }
  }
  </code></pre>
  
  <p><strong>TICKET CLASS</strong></p>
  
  <pre><code>@Entity
  public class Ticket {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int ticketId;
      private String title;
      private String message;
  
      @Enumerated(EnumType.STRING)
      private TicketPriority priority;
  
      @Enumerated(EnumType.STRING)
      private TicketStatus status;
  
      @Enumerated(EnumType.STRING)
      private TicketType type;
  
      @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "dd-MM-yyyy | HH:mm",timezone="Asia/Kolkata")
      @Temporal(TemporalType.TIMESTAMP)
      private Date timestamp;
  
      @JsonIgnore
      @ManyToOne
      @JoinColumn(name = "owner_id")
      Employee owner;
  
      @OneToMany(mappedBy = "ticket", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
      private Collection&lt;Comment&gt; comments = new ArrayList&lt;&gt;();
  
      public Ticket() {
          super();
          this.title = "";
          this.message = "";
          timestamp = new Date();
          this.status = TicketStatus.RAISED;
      }
  }
  </code></pre>
  
  <p><strong>COMMENT CLASS</strong></p>
  
  <pre><code>@Entity
  public class Comment {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int commentId;
      private String message;
  
      @OneToOne
      @JoinColumn(name="comment_owner")
      Employee employee;
  
      @ManyToOne
      @JoinColumn(name="ticket_id")
      Ticket ticket;
  
  }
  </code></pre>
  
  <blockquote>
    <p>Query i am using is <strong>return getCurrentSession().get(Ticket.class, id);</strong></p>
    
    <p>This is the toString of the Ticket object i am getting</p>
    
    <p>Ticket [ticketId=5, title=WFH, message=i need to work from home tomorrow, priority=IMMEDIATE, status=RAISED, type=WFH_REQUEST, owner=Employee [empId=1, employeeCode=123, fullName=emp, emaillAddress=emp, password=emp, role=2, tickets=], comments=[]]</p>
  </blockquote>