-->
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: OneToOne bidirectional relation
PostPosted: Tue Apr 05, 2011 11:08 am 
Newbie

Joined: Wed Mar 30, 2011 6:23 am
Posts: 3
Assume there are two entities with OneToOne relation:
Code:
   @Entity
   public class A {
      private long code;
      private B b;

      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)   
      public long getCode() {
         return code;
      }
      
      public viod setCode(long code) {
         this.code = code;
      }
      
      @OneToOne(fetch=FetchType.LAZY, mappedBy="a", cascade={CascadeType.ALL})
      public B getB() {
         return b;
      }

      public void setB(B b) {
         this.b = b
      }
      
      // additional setters and getters
   }

   @Entity
   public class B {
      private long code;
      private A a;
      
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)   
      public long getCode() {
         return code;
      }
      
      public viod setCode(long code) {
         this.code = code;
      }   
      
      @OneToOne(fetch=FetchType.LAZY)
      @JoinColumn(name="acode", nullable=false)   
      public A getA() {
         return a;
      }

      public void setA(A a) {
         this.a = a
      }
      
      // additional setters and getters   
   }

The problem is that when I am fetching A object, the B object is loaded as well even though I didn't call getB() method. Why hibernate performs this redundant query?
Is this a regular behaviour with bidirectional relations?


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.