• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question for the "Java Made Easy" book author

 
Razvan Popovici
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I worked with hibernate more than 3 years, still I have some questions regarding performance:

- deletion - is it any way to delete without reading the data. I mean:
Delete * from customers where name='John'
is much faster than selecting data, fetching it, than deleting each record based in ID.

- scrollable cursors
if the result of the select query is expected to be huge so it is unpractical to display the whole data, programmer may decide to fetch the first nnn records to display them in an user interface, than once the user pages or scrolls the control, the required data is fetched on demand. Practically the programmer can access the cursor in a random (as opposed to sequential) fashion. How does Hibernate fit in this approach? Please note this approach is bound to the database server capability, old databases such as Oracle 8 does not support it (at least I tried and didn't succeed few years ago).

- insertion issue
It seems the memory of the process is increasing once we add new entries to the database.

- instanceof does not work if using class inheritance. The classes seems to be always an instance of the base class, even if Hibernate could 'know' what class actually to instantiate, by using a discriminator.

It seems except Update, I have covered with questions all possible CRUD opperations
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- deletion - is it any way to delete without reading the data. I mean:
Delete * from customers where name='John'
is much faster than selecting data, fetching it, than deleting each record based in ID.


What is it they say? To a man with a hammer, everything looks like a nail? In this vain, Hibernate isn't always the right tool for the job. Doing large inserts or backups might be better done by ETL tools or database specific tools. Having said that, though, Hibernate does provide an executeUpdate and an executeDelete method that is designed for batch updates, and will provide better performance that using per-entity calls.

Practically the programmer can access the cursor in a random (as opposed to sequential) fashion. How does Hibernate fit in this approach?


To address pagination, I always suggest using the Hibernate Critieria API. You an set the record number to return, along with the size of the result. Here's how it would look in code:




instanceof does not work if using class inheritance. The classes seems to be always an instance of the base class, even if Hibernate could 'know' what class actually to instantiate, by using a discriminator.


A frustrating issue, indeed. I've seen workarounds by using the equals() method instead, and overriding the hashcode method. Not quite the same as instanceof, but it can work.



It seems the memory of the process is increasing once we add new entries to the database.


An interesting issue indeed. Is the Hibernate Session being closed at the end of the insertion, or is it an open session? If you're keeping the session open, Hibernate will keep adding updated entities to the cache. Perhaps that's the issue. If not, maybe this would be a good question for a thread of its own?

Thanks for the questions! Keep them coming!

-Cameron McKenzie
[ June 03, 2008: Message edited by: Cameron Wallace McKenzie ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic