-->
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: Batch reading of collection with lazy OneToOne relation
PostPosted: Wed Jun 10, 2009 10:57 am 
Newbie

Joined: Fri May 29, 2009 4:22 am
Posts: 1
Hi everbody,

my problem is the following: I have an entity class "Partner" which has a bidirectional OneToMany relation to entity class "Role". "Role" is abstract and has a concrete subclass "Employee".

The Entity class "Employee" has a unidirectional OneToOne-Relation to entity class "BankAccount".
I have a use-case-based NamedQuery which retrieves all Partners:

Code:
@NamedQuery(name = "getAllPartners", query = "SELECT p FROM Partner as p"),


The collection attribute getter for "Roles" in entity class "Partner" is annotated like this (Focus on @BatchSize-annotation):

Code:
   @OneToMany(mappedBy = "partner", cascade = { CascadeType.MERGE,
         CascadeType.PERSIST }, fetch = FetchType.LAZY)
   @BatchSize(size = 100)
   @IndexColumn(name = "id")
   @JoinColumn(name = "partner_id", referencedColumnName = "id")
   public Set<Role> getRoles() {
      return roles;
   }


In my specific Data Access Object method I am executing the query and iterating through the 50 results like this:

Code:
      Query q = em.createNamedQuery("getAllPartners").setMaxResults(50);

      List<Partner> l = q.getResultList();
      //   BatchRead
      for (Partner partner : l) {
         partner.getRoles().size();
                        // Here is my PROBLEM
         for (Role role : partner.getRoles()) {
            ((Employee) rolle).getBankAccount();
         }
      }


Without trying to also get the "BankAccount" entity ,everything works just fine and Hibernate generates a SELECT with a huge WHERE...IN(...)-clause.

With it, it ends up in a LazyInitializationException because no additional SELECT for the BankAccount is placed at any time and I am accessing the BankAccount on a detached object.

So basically the problem I am experiencing, is that in my case there seems to be no opportunity to also batch read the associated entity class "BankAccount" without using a static eager. Or is there a solution for this kind of problem?

Any help is appreciated!!! Thanks a lot in advance!


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.