Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One to many - many to one performance

 
Bhuvana Saairaam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm having doubt on OneToMany and ManytoOne
Below are the following codes

it works fine for save/update/search..
In search
using the hibernateTemplate().findbyid(class,id);

while searching. i see the model objects (children) having the bookingObject bec of manytoone.
its is okay for one or two collections.
but am having 16 sets in the Booking itself. which take more time to get the whole data.
just before it take <1 sec to get the booking.

when i added child having children. eg. booking(parent)-trackvehicle(child)-(trackvehicle child1,child2,child3) also having more records perchild.
it takes 35secs to get the whole booking using getHibernateTemplate.findbyid(class.id).
it is bec child1 has transportvehivcle ref,the transportvehicle has the bookingref (
i see this in the log ,child1 has transportvehicle object that transportvehicle object has booking object) much heavier object i think.and so it is

I need the explanation and solution .

Can any one Help me.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome

So your problem is want to load faster? One way is to fetch the first X records instead of the "all" records.

Another maybe instead of setting all the attributes just set the ones seen by user in the search results page.

Yet another depending on your app, use AJAX or equivalent to load the the booking ratings.
 
Bhuvana Saairaam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Welcome

So your problem is want to load faster? One way is to fetch the first X records instead of the "all" records.

Another maybe instead of setting all the attributes just set the ones seen by user in the search results page.

Yet another depending on your app, use AJAX or equivalent to load the the booking ratings.


Yes need to load faster.Probably fetching X records is a good way.But is that only?.Another one, to show the needed only to the user ,if they need more, then fetch the related data and to show again
its a web application.Is there any other way to achieve this relationship.
is there any code change needed.?
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's simple for search pages because you can always use pagination of X records. Meaning only fetch X at a time. When user clicks page 2, fetch the next X records and so on.

However if you use scrolling which I don't recommend because this way you really can't fetch X but have to fetch all.

Thinking more, if Hibernate (that's what you using?) has the concept of data model or lazy loading, you can look it that. Either way should be similar to the fetch X records approach.

The only thing I see need changing is the SQL telling how many to fetch and the from/to record number.
 
Bhuvana Saairaam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:It's simple for search pages because you can always use pagination of X records. Meaning only fetch X at a time. When user clicks page 2, fetch the next X records and so on.

However if you use scrolling which I don't recommend because this way you really can't fetch X but have to fetch all.

Thinking more, if Hibernate (that's what you using?) has the concept of data model or lazy loading, you can look it that. Either way should be similar to the fetch X records approach.

The only thing I see need changing is the SQL telling how many to fetch and the from/to record number.


yes, using hibernate.Sure will look at that.
so this is the behavior of hibernate? cant we optimize?
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's all in the line



The attributes in the <set> tag are something you should look into in details.

If you have a copy of "Java Persistence with Hibernate" have a look at ch 13 "optimizing fetching and caching"
 
Campbell Ritchie
Sheriff
Posts: 51450
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this.
 
Bhuvana Saairaam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:it's all in the line



The attributes in the <set> tag are something you should look into in details.

If you have a copy of "Java Persistence with Hibernate" have a look at ch 13 "optimizing fetching and caching"


yes.. for sure.. thank you K.Tsang. I will post the solution if i find the best. :-)
 
Bhuvana Saairaam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Please read this.

hi ritchie. I dont know how to get you in this post also am unaware of K.Tsang immediate Response.also this is my very first step in coderanch.
 
Bhuvana Saairaam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've gothru.. fetching strategies...
so far. i concluded that join is best for my situation..
bec select hit back DB every time it find . so hits first query for booking, hits second query to DB... etc.
so if using Join in the fetch , the query will be one.it may improve the performance little bit.
also i logged the time and noticed that it get reduced. to more mills.
another. am using some formulas in some hbm files. there join will not give you hands. at that time
you have to give fetch subselect .
Also many thanks to Tsang
Hope you Enjoy with this post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic