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

Hibernate is great, but Native query support is limited

 
Diana McHenry
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My company is using Hibernate as the ORM tool for our latest project. Unfortunately, we are constrained by our obligatory use of a badly designed legacy database. As such, we have several unwieldy queries (some over 4 pages long with 10+ joins).

I spent a day last week attempting to convert our existing JDBC code to a native Hibernate query, but was forced to abandon this effort as Hibernate requires that ALL fields in the resulting object, as well as ALL fields in its member objects be populated by the query. Given the size of the objects in our domain layer, this would have had a significant performance impact.

Does anyone know a way around this, or why Hibernate has this restriction?

Thanks!

Diana
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Diana, I'm moving this thread over to our ORM forum which is dedicated to persistence frameworks such as Hibernate (this is for the "other" kind of application frameworks;)

Please follow-up over there.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hibernate requires that ALL fields in the resulting object, as well as ALL fields in its member objects be populated by the query

Not sure I follow what you mean by this. Are you worried about populating associations or just the attributes of one object?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to load a subset of an object's attributes, you can specify them separately in the select clause and Hibernate will return a List of Lists, I believe. I haven't tried it, but I recently saw an example posted in this forum a week or two ago.

For associations, you can use lazy-loading.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do 'select class.field1, class.field2 from package.class'

You get back a List that contains Object[]'s. Primitives will be wrapped in their wrapper classes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic