-->
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.  [ 5 posts ] 
Author Message
 Post subject: basics - multiplicity of unidirectional association and....
PostPosted: Mon Apr 16, 2007 7:08 am 
Newbie

Joined: Sun Apr 15, 2007 7:11 pm
Posts: 4
Hi,

Please explain me this -

From chapter 1 page 17..
It isn’t possible to determine the multiplicity of a unidirectional association by looking only at the Java classes.

Then the author says ....

Java associations can have many-to-many multiplicity.
For example, the classes could look like this:

public class User {
private Set billingDetails;
...
}
public class BillingDetails {
private Set users;
...
}

Does the second sentence explains what the first sentence has to say, if yes...how?

Or simply put...why the author says what he says in the first sentence

Also: Please see the questions inline following the bolds

For example, if you need to retrieve a User and aren’t interested in the
user’s billing information, you can write this simple query:
select * from USERS u where u.USER_ID = 123
On the other hand, if you need to retrieve a User and then subsequently visit each
of the associated BillingDetails instances (let’s say, to list all the user’s credit
cards), you write a different query:
select *
from USERS u
left outer join BILLING_DETAILS bd on bd.USER_ID = u.USER_ID
where u.USER_ID = 123
As you can see, to efficiently use joins you need to know what portion of the object network {in our example what would be that portion?}you plan to access when you retrieve the initial {what is the significance of this word?} User—this is before you start navigating the object network!{the object n/w formed in memory by executing the above query or the resulting java object n/w?}
On the other hand, any object persistence solution provides functionality for fetching the data of associated objects only when the object is first accessed. However, this piecemeal style of data access is fundamentally inefficient in the context of a relational database, because it requires executing one statement for each node or collection of the object network that is accessed. This is the dreaded n+1 selects problem.
This mismatch in the way you access objects in Java and in a relational database is perhaps the single most common source of performance problems in Java applications. {could you give an example to explain how the mismatch leads to this performance problem?} There is a natural tension between too many selects and too big selects, which retrieve unnecessary information into memory. {could you put it in other words, I mean if both are bad what is the tension?}

Thanks,

Ammar


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 5:02 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Since I've already explained all that stuff in the book, I don't know how to explain it any different. Maybe someone else wants to have a go and break this down into smaller pieces...

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 5:11 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Well, I can spare five minutes right now but that's really all from me:

- "What portion of the object network..." The user and his billingdetails, read the query.

- "initial" The user instance that we wanted to _initially_ load.

- "the object n/w formed in memory by executing the above query or the resulting java object n/w" That is the same thing.

- "could you give an example to explain how the mismatch leads to this performance problem" Really, the second half of the book is only about this problem, with hundreds of examples. This is a sentence from the first chapter, you need to actually read the rest of the book to understand it fully.

- "could you put it in other words, I mean if both are bad what is the tension" Well, if you have two choices, and there are both bad, there is tension, no?

OK, so I now see that all your questions are about the first chapter. Please continue reading, there is a reason why the book has more than one chapter :)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: multiplicity of unidirectional association
PostPosted: Mon Apr 16, 2007 6:15 pm 
Newbie

Joined: Sun Apr 15, 2007 7:11 pm
Posts: 4
Thanks Christian,

If you could explain one thing that was left..

From chapter 1 page 17..
It isn’t possible to determine the multiplicity of a unidirectional association by looking only at the Java classes.

Then the author says ....

Java associations can have many-to-many multiplicity.
For example, the classes could look like this:

public class User {
private Set billingDetails;
...
}
public class BillingDetails {
private Set users;
...
}

Does the second sentence explains what the first sentence has to say, if yes...how?

Or simply put...why the author says what he says in the first sentence.

Regards,

Ammar (I'll definately read whole of the beautiful book)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 6:27 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Take a pen, add to the sentence "It isn’t possible to determine the multiplicity of a unidirectional association by looking only at the Java classes" the following ", which should be obvious, because unidirectional implies that you are looking at one class only. So you can't see the other 'side', and you obviously can't find out what the multiplicity is going to be."

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.