-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Relationship Mapping Problem
PostPosted: Mon Mar 02, 2009 10:48 am 
Newbie

Joined: Fri Feb 20, 2009 6:25 am
Posts: 10
Hi all,

I have one issue in dealing with Hibernate associations. I just wanted to know that is there any drawback of using Associations by Hibernate mapping file? One of my senior is saying that there will be a lot of performance problems in using associations by Hibernate.

Other approach is to use Seperate mapping class that corresponds to the table for the mapping. And map this class as our persistent class in the mapping file, argument is that we will not need to jump into the hotch potch of Lazy loading and sets and lists. Is this the right approach to deal with relationships between classes?

I just want to know your openions. It would be better if you can explain it with logical arguments and examples.

_________________
Thanks & Regards,

Vishal Shukla


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 6:40 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I don't quite understand what you mean by associations. All relationships are associations at least in my mind. If you could provide an example of instances you are talking about then maybe we could help.

Hibernate is used by 1000's of apps. I believe hibernate is extremely fast. It's been around for quite awhile and is a very mature product.

I had trouble with lazy loading like quite a few people have, but it mostly comes from a misunderstanding of how it works. Lazy loading is a feature and a great one at that if you understand how it works and how to manipulate it.

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 7:13 pm 
Regular
Regular

Joined: Tue Dec 30, 2008 8:14 pm
Posts: 50
When loading nested collections (class A conains a collection of B. B contains a collection of C. And so on), I had better performace with using HQL and loading data into a separate class, and then building the nested collections in memory. This worked a lot better than mapping each class, because the number of SQL queries reduced to 1 (from 1000s). But, while saving data, mapping domain objects directly worked better even in this case.

LinHib.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 7:19 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
LinHib - that is correct but it's also good to point out that you can also turn off lazy fetch and then only one sql statement is made without having to select each class in the hql.

Hibernate gives you a lot of options. Like I said I don't find it has performance issues. It just has a learning curve to understand how to use it properly.

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 7:30 pm 
Regular
Regular

Joined: Tue Dec 30, 2008 8:14 pm
Posts: 50
ethnarch,
Agree. In the above scenario, I needed to load all the data at the same time, and send to a think client. So lazy loading was not an option.

LinHib.


Top
 Profile  
 
 Post subject: Re: Hibernate Relationship Mapping Problem
PostPosted: Mon Mar 09, 2009 2:15 am 
Newbie

Joined: Mon Mar 28, 2005 8:54 pm
Posts: 4
Location: Idaho
Vishal,

In business it is all about relationships. When a customer is associated with a product the business receives value. The associations, relationships, Hibernate supports are one-to-one, one-to-many, many-to-many, and many-to-one.

You did not say which one you are using, if they are unidirectional, or if they are bidirectional. Most associations are binary but some are ternary where an object describes the relationship between two other objects. Simple binary associations of one-to-many and many-to-one are realized in a relational database as foreign key reference between two tables. The binary many-to-many association must be realized in a relational database with a junction table containing foreign keys to the ends of the binary association. The ternary association is realized in a relational database with a junction table containing additional columns describing the association.

Your business object model should reflect the way the business associates its objects not how they must be stored. The only useable data are data loaded into the application. Can you use clothes in your closet? Not until you take them out and put them on. Do you put the clothes on with their hangers attached? Of course not. Then don't do it with your business objects; leave database constructs in the database.

One last thing, make sure the information that is in you objects really belongs to that object. For the courses - students relationship where does the teacher, room number, date-time, and grade belong? To the course? To the student? Or to the association?

Poor performance is not from Hibernate or object associations; it is from sending large object graphs to the presentation tier.

Give more specific information and you will get more specific help.

Dave


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 09, 2009 6:05 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
Dave,

Just want to point out that was a great way to explain it. Maybe I'll use that analogy in the future.

too bad it doesn't seem like vishal is even monitoring this thread.

_________________
Please rate my replies as I need points for all of my questions also.


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