Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Performance with Hibernate

 
Ranch Hand
Posts: 241
  • 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,
 
author
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: 241
  • 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,
 
blacksmith
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: 241
  • 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,
 
author
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it won't.
 
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: 241
  • 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,
 
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
 
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
 
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
 
Men call me Jim. Women look past me to this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic