-->
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.  [ 4 posts ] 
Author Message
 Post subject: inverse=true idea
PostPosted: Tue Jun 06, 2006 10:26 am 
Beginner
Beginner

Joined: Tue Apr 25, 2006 10:46 am
Posts: 28
Hi,

Please excuse me if the quesstion seems dumb. I examined
Category.java and Item.java source code and find
both have

Code:
public void addCategorizedItem(CategorizedItem catItem) {
      if (catItem == null)
         throw new IllegalArgumentException("Can't add a null CategorizedItem.");
      this.getCategorizedItems().add(catItem);
   }


but association mapping for Item and Category also have inverse="true", which
imply that changes made at the CategorizedItem Collection on both
Item and Category should have no effect to database, hence code like

Code:
addCategorizedItem(..) above


should not propagate change to database. That's the idea presented in
page 110 of Hibernate in Action. Rather, I expect code like

Code:
   class CategorizedItem ... {
      
      public void addCategory(Category cat) {
         getCategories().add( cat );                  
      }
      
      public void addItem(Item item) {
         getItems().add(item);
      }
   
      ......         
   
   }



to propagate change to database. So what's wrong with my
understanding???

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 4:29 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The code is required to set the correct pointers in the Java application. The fact Hibernate ignores one of these pointers doesn't change the requirement.


Top
 Profile  
 
 Post subject: reply
PostPosted: Tue Jul 25, 2006 6:53 pm 
Beginner
Beginner

Joined: Tue Apr 25, 2006 10:46 am
Posts: 28
Thanks,

Just 1 last question,

How come the addCategorizedItem(CategorizedItem catItem) method didn't try to set a bidirectional ref for catItem argument ?

E.g.

Code:
public void addCategorizedItem(CategorizedItem catItem) {
      if (catItem == null)
         throw new IllegalArgumentException("Can't add a null   
        CategorizedItem.");

      this.getCategorizedItems().add(catItem);
     
      // I wud expect this line below since inverse="true"
     // in Category mapping
     catItem.setCategory(this);
}



Thanks,

Sam


Top
 Profile  
 
 Post subject: reply
PostPosted: Tue Jul 25, 2006 7:33 pm 
Beginner
Beginner

Joined: Tue Apr 25, 2006 10:46 am
Posts: 28
No need to reply,

I figure this out now. Silly me.


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

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.