-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Annotation & Criteria API
PostPosted: Wed Mar 19, 2008 11:00 pm 
Newbie

Joined: Wed Mar 19, 2008 10:46 pm
Posts: 5
Hello, I have a question regarding hibernate annotation & criteria API.

My hibernate class looks like this (pseudocode):


Code:
public class A{
....
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="reporting_year_id", referencedColumnName="reporting_year_id", updatable=false, insertable = false,columnDefinition="number(10,0)")
    @ForeignKey(name = "ctl_activity_reporting_year_fk")
    protected B b;
}

public class B{
    .....
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
    @JoinColumn(name = "reporting_year_id", referencedColumnName = "reporting_year_id")
    @ForeignKey(name = "bus_cycle_reporting_year_fk")
    protected List<C> c;
}


public class C{
  ....
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
    @ForeignKey(name = "mgmt_unit_bus_cycle_fk")   
    @JoinColumn(name = "business_cycle_id", referencedColumnName = "business_cycle_id")
    protected List<D> d;
}



I perform the criteria on A.

Code:
Criteria criteria = session.createCriteria(A.class);

if(  ... some condition...){
   Criteria bCriteria = criteria.createCriteria("b");
   bCriteria .add(Restrictions.eq("reportingYearID", req.getReportingYearID()));

    Criteria cCriteria = bCriteria .createCriteria("businessCycle");
    cCriteria .add(Restrictions.in("businessCycleID", req.getBusinessCycleID()));
}


I dont want the query on A (i.e. the criteria above) to fetch B, C, D, and so on. But as soon as I specify a criteria on B (the if condition above), then hibernate will do the join...(i saw this on log4j output).
I still need the EAGER fetch type on B and C.

I tried to specify setFetchMode() on the association to be LAZY, but it didnt have any effect.


Is there any way to override this annotation-driven fetch strategy?



Thanks a lot!


Alex.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.