0

I have two entities called EmployeeEntity and EmployeeDeparmentEntity.If I fetch the employee I want fetch all departments which are active.I have used bi-directional mapping for both entities.

EmployeeDeparment

@Entity
public class EmployeeDeparment implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne
    @JoinColumn(name = "employeeid")
    private EmployeeEntity employeeentity;

    @Temporal(javax.persistence.TemporalType.DATE)
    private Date addeddate;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date modifieddate;
    @ManyToOne
    private EmployeeEntity reportingTo;

    @ManyToOne
    private DepartmentMaster departmentID;
    private boolean status;

}
perissf
  • 15,979
  • 14
  • 80
  • 117
user3214269
  • 219
  • 2
  • 8
  • 23
  • 1
    See my edits: I have removed unnecessary getters/setters and imports, not relevant to the understanding of the problem. I have also corrected a misspelling in the question title and added a tag. If you want to getter more help sooner, help us understand what have you tried so far. – perissf Mar 25 '14 at 08:39

1 Answers1

0

As per your situations i came up with the following criteria hibernate query which might help in your case.

Criteria criteria = session.createCriteria(EmployeeDeparment.class);
criteria.add(Expression.eq("status",true));  //all active department
criteria.add(Expression.eq("employeeentity.id",1234));  //set the employee id 

List lisObj = criteria.list();


Iterator it=lisObj .iterator();

while(it.hasNext())
        {
            EmployeeDeparment p=(EmployeeDeparment)it.next();
            p.get(.........);
            p.get(.........);
            p.get(.........);
        }

Let me know if you face any further issue...

Rahul Wagh
  • 470
  • 1
  • 6
  • 23