-->
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: Applying Hibernate.initialize() to whole collection.
PostPosted: Mon May 07, 2012 9:50 pm 
Newbie

Joined: Tue Jan 13, 2009 1:30 pm
Posts: 3
Hi,

I have an EmailForm Object which have mapped one-to-many Lazy Collection with EmailFormDetails object.
Actually i required to retrieve the collection of EmailForm Object with pre initialized EmailFormDetails.
is that any way i can simplify the code or need to iterate each Email Form Object and apply Hibernate.initialize(EmailForm.getEmailFormDetails()).

Also how the performance if i approach this way since the collection of objects may around 20000+ records sometimes.

Please help on this.

Code:
EmailForm.java
=============
   @OneToMany(mappedBy = "emailForm", fetch = FetchType.LAZY)
   @Cascade(CascadeType.ALL)
   private Set<EmailFormDetail> emailFormDetailList = new HashSet<EmailFormDetail>();

EmailFormDetail.java
===============   
   @ManyToOne
   @JoinColumn(name = "EMAIL_FORM_ID")
   private EmailForm emailForm;

Service API

   public List<EmailForm> getAllEmailFormAndDetailsDataByDates(Date fromDate,Date toDate)
         throws ApplicationException {
      logger.info("findAllBetweenDates()-fromDate:" + fromDate + "toDate:"
            + toDate);
      List<EmailForm> toReturn = null;
      try {
         toReturn = getEmailFormDAO().findAllBetweenDates(fromDate,
               DateUtil.getInstance().adjustDays(toDate, 1));
         //Hibernate.initialize(toReturn.size()); //NOT Works
         //This is working.but any other better way we have?
         for(EmailForm emailForm : toReturn)
            Hibernate.initialize(emailForm.getEmailFormDetailList());

      } catch (DBException e) {
         throw new ApplicationException(e);
      }
      return toReturn;
   }   




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.