-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Beginner question about data object structure.
PostPosted: Wed Aug 03, 2005 6:01 am 
Newbie

Joined: Wed Aug 03, 2005 5:45 am
Posts: 2
Hi all.

I'm just looking for some general advice. My situation is that I've been asked to re-implement an existing persistence layer using Hibernate. It's all going pretty well so far (Hibernate guys: you are amazing, it is an excellent product), but I have the following grey area to deal with:

The data objects I have inherited already conform to basic Bean standards, so all good there, but they contain int IDs that link to each other's database records, rather than references. So for example the Apple class has a getParentAppleId() method which corresponds to the primary key in the APPLE table, rather than a getParentApple() method which returns an instance. My dilemma is whether I (1) keep things this way and try to handle all relationships using joins and similar techniques or (2) re-implement the data objects also so that they all have variables which point to instances of the objects to which they are related, rather than ID's to database entities.

I have tried (1) to some extent already and I'm having a few problems. For instance, is it possible to set up associations in your mapping file if you only have an ID of the other object's database entry, not a reference to it?

Thanks in advance for any help you are able to give.


Paul


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 10:43 am 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
I just went through the same process. We refactored our object model so that the foreign ID's were replaced with real associations. It was a giant pain up front, but so much nicer now.

For one thing, I suspect that there's currently a lot of code in your app that deals with fetching those associated objects when you need a label, name, etc. All this code goes away and gets replaced with simple calls to getters.

The ability to map an association and then let Hibernate deal with how to fetch those associated objects when you need them made it totally worth the refactoring pain. (This project had a smallish object model; around 50 tables.)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 11:16 am 
Newbie

Joined: Wed Aug 03, 2005 5:45 am
Posts: 2
Thanks jdl.

I am going to go down that route. In fact, in the last three hours (as I was stuck anyway) I've made a start on it and already I am seeing the benefits.

It's nice to hear some reassurance that this is the way forward though, so thanks again.

Paul


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.