This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Performance and the fly likes Hibernate: When should I load my records? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Hibernate: When should I load my records?" Watch "Hibernate: When should I load my records?" New topic

Hibernate: When should I load my records?

Mario Schwaiger

Joined: Jun 14, 2010
Posts: 14
I'm developing a web project in JSP which uses Hibernate to cache and edit data records. The user just sees one record including all its lines on a page - if he wants to see another record the page is reloaded. Every record contains a list of 1-7 lines of data from a(n updateable) view which needs to be changed sometimes. Now it comes to the point where I have to design the efficiency of the whole thing. I guess I have three (four?) options:

1. Load the whole data in the beginning and just perform list.add/deletes as something occurs. Here would the question be how the data is loaded in this moment. Just by using session.createQuery( "Select E From Elements E") it's not really queued. Also I am a bit afraid of potential timeouts. I am using c3p0 and as a timeout occurs it can handle it (even though it takes ~30s until the successful reconnect...)

2. The other option would be to load and change everything on demand and use HQL to catch the Item of desire in the moment the user changes/inserts a record:

Here I guess I'd lose some time while the loading of the current page. (The view eats some ressources) but win time due to the efficiency of HQL (or am I wrong?).

3. A mixed solution of both. All the records have to be loaded into the cache in the beginning (again the question as mentioned above how they are really loaded - including the @OneToMany-Lists of its records) and the update is done with the HQL statement.

4. Something completely different?

Don't get me started about those stupid light bulbs.
subject: Hibernate: When should I load my records?
Similar Threads
Lazy-loading of collections generated by HQL ?
Hibernate:Problem in updaing data to the database
Hibernate keeps updating database.
Delete cached data and load from database
How to pass Data from Hibernate query.list to the JSP Page