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

POJOs and Legacy Databases

 
Darryl Thompson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Chris Richardson,

I am working on a port of a mission-critical legacy app from EJB to Hibernate 3.0. One of the more interesting issues we are facing is handling situations where a table (entity) has many (no pun intended) many-to-one foreign key associations. The client does not want to incur the overhead of reading each foreign key relationship to instantiate (or attach) a hibernate object when the foreign key is available via a value (or Data Transfer) object.

As a work-around the lead developer has resorted to adding an additional column to the hbm file that is used instead of the object reference column (there is a way to alternate which one is actually passed to the database).

Is there a "better" way of handling this kind of legacy issue?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not set up a database view and build Hibernate instances off the view instead of the tables?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why not set up a database view and build Hibernate instances off the view instead of the tables?

Because not all views are updatable?


Is there a "better" way of handling this kind of legacy issue?

Absolutely. Just use the built in proxy objects functionality. When you load an object that has an association, a proxy object is created for this association which has the id property set. Just get it from that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic