Hi,
I have a entity which has many ManytoOne relationships with other entities. Like:
public class Test{ private Long id; private Package package; private SystemInUse systemInUse; @Id @GeneratedValue(strategy = AUTO) @Column(name = "security_id", unique = true, nullable = false) public Long getId() { return this.id; } @ManyToOne(fetch = FetchType.EAGER) @Fetch(FetchMode.JOIN) @JoinColumn(name = "package_id", nullable = false) public SecurityType getPackage() { return this.package; } @ManyToOne(fetch = FetchType.EAGER) @Fetch(FetchMode.JOIN) @JoinColumn(name = "systemInUse_id", nullable = false) public SecurityType getSystemInUse() { return this.systemInUse; } } in my main entity class. In one query i need to fetch all the records in this 'Test' table and attached records for 'Package' . I use the following criteria Criteria secCrit=securityDao.getSessionFactory().getCurrentSession().createCriteria(Test.class); secCrit.setFetchMode("package", FetchMode.JOIN); secCrit.setFirstResult(firstResult); if(maxResults!=0) secCrit.setMaxResults(maxResults); return secCrit.list();
It fires a query for fetching these details but the query includes Join to SystemInUse table as well. I am now confused on how to use setFetchMode of Criteria. Is there any way I can achieve this as the number of records is high and I cannot have the n queries model here? Thanks Monika
|