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

Performance with Hibernate

 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Focusing the cost to retrieve the data and not in transport it, is there any difference in performance with Hibernate if i project only one field or many fields ?
Example: In tradional SQL I think that the query "SELECT * FROM ..." has the same performace as "SELECT anField FROM ..." because the DB load an entire frame (or the entire row) and not only the collum that was specified.
How does hibernate handle this ?

Regards,
 
Gavin King
author
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, most of the effort in retrieving data is effort on the part of the database, so yes, your experience with SQL carries over into ORM. Optimizing column reads is not usually worth the effort. (Though it is possible; HQL supports projection, just like SQL.)
 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Gavin King,

One more doubt.
Assume that I have an one-to-one relationship, like client <-> address
If i project only fields from the table client, will hibernate make a join with address even the fields that i�m projecting is only in the table client ?

Regards,
 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vinicius,

Check out this with regard to performance issues.

Cheers,

Gian Franco Casula
 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gian Franco Casula:

Check out this with regard to performance issues.


Thx Gian,
Great article. There are many tips of performace but it doesn�t mention nothing about my doubt.

Regards,
 
Christian Bauer
author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it won't.
 
Fabrizio Gianneschi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vinicius Boson:
Thx Gavin King,

One more doubt.
Assume that I have an one-to-one relationship, like client <-> address
If i project only fields from the table client, will hibernate make a join with address even the fields that i�m projecting is only in the table client ?

Regards,


I solved this problem just today experimenting with Hibernate... that's my solution:

When you want to realize "part-of" relations (like user--address) you can declare a <component> into the User definition (User.hbm.xml) and map it on the adress fields. (see Hibernate docs at
http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-component)

So Hibernate doesn't make any join... it just creates an User class instance and an Address class instance into it.
 
Eusebio Floriano
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Fabrizio Gianneschi:


So Hibernate doesn't make any join... it just creates an User class instance and an Address class instance into it.


But how does hibernate load Address class ? It has to make an join, right ?
It wont only if i need an field from table user.
But hibernate does not know if i want only an field from user, so if i mapped the address class in user.hbm (like one-to-one or many-to-one), hibernate will **ALWAYS** load address, won�t it ?

Regards,
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you map the Address as a Component, then it goes to the same table than the User. i guess no joins then....


The <component> element maps properties of a child object to columns of the table of a parent class


cheers

pascal
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a 1-1 relation is somehow (at least theoretically) different than a composition. This differentiation can be found also in UML.

You must decide which is the lifecycle of both your entities and this will help you determine how to better persist them.

/pope
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example : config mapping 1:1

http://www.hibernate.org/hib_docs/reference/en/html/example-mappings.html#example-mappings-authorwork
 
Fabrizio Gianneschi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ali Pope:
I think a 1-1 relation is somehow (at least theoretically) different than a composition. This differentiation can be found also in UML.

You must decide which is the lifecycle of both your entities and this will help you determine how to better persist them.

/pope


Yes, it's true. Use a 1-1 association when both entities could exist in your model even without the other one. For example, consider "man" and "woman" entities and the relation "isMarriedWith".

Instead, consider composition when one entity cannot exist alone. So this is not really an entity, we call it a "component". Like the example I mentioned in my last post.

So, my solution was only for composition, not to 1-1 relations, sorry.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Fabrizio Gianneschi:


Yes, it's true. Use a 1-1 association when both entities could exist in your model even without the other one. For example, consider "man" and "woman" entities and the relation "isMarriedWith".

Instead, consider composition when one entity cannot exist alone. So this is not really an entity, we call it a "component". Like the example I mentioned in my last post.

So, my solution was only for composition, not to 1-1 relations, sorry.


Happy you caught my message ;-).

./pope
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic