Forums Register Login

Factoring Out Address Information

+Pie Number of slices to send: Send
I'll bet this is a common question, but I couldn't figure out how to search for it...

Say I've factored out (street) "Address" from several classes in my OOD. Is it also wise to factor out Address (into its own table) in the RDB? I'm fairly new to this stuff, and I don't see not, but I've had Address unfactored in past (procedural) applications, and the switch seems weird.

Out of curiosity, does Hibernate support both RDB implementations (Address-as-a-separate-entity vs. Address-as-a-set-of-fields-within-other-entities) for the "factored Address" OO class model?

Thanks,
Jamie
+Pie Number of slices to send: Send
hi
if i understand your question correct, then you are looking for something hibernate calls Component.



pascal
+Pie Number of slices to send: Send
Yup, a component is what you want. And you should be able to have it in the same table or another table with a one-to-one relationship.
+Pie Number of slices to send: Send
Yes, that's what I'm after, thanks.

In the case of, say, Address, is there any prevailing preference (entity vs. component)? I'm leaning toward a separate entity, but one-to-one relationships seem odd to me. (Is that something I just need to get over?)

Thanks again,
Jamie
+Pie Number of slices to send: Send
Keep in mind that the Hibernate model doesn't have to match the database model. If you put the address into its own table, the database has a one-to-one relationship. But in Hibernate you'd just embed the component directly into its owner. To load the address, you'd have to load its owner and do getAddress().

Even if you allowed for multiple addresses per owner, I believe you can still model it as a set of components without a one-to-many relationship. I'm not positive there as I haven't used components yet. All my objects are entities as I ported an EJB application (with entity beans) straight over and was given no time to experiment unfortunately.

So I think you only need to create a separate entity if you want to be able to load addresses directly. Again, this is new to me so I'd read up on the docs and perhaps hope one of the more experienced Hibernators chimes in.
Always look on the bright side of life. At least this ad is really tiny:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 763 times.
Similar Threads
format attribute in bean:write not working
Problem in creating simple entity bean/WSAD
How to check if session exists?
JDBC Driver for Oracle RDB
Carry content onto another page?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:13:24.