oop - designing classes and hibernate mappings -


while going through code in hibernate books ,i noticed strange things entity classes. example customer has address.the mapping given is

public class customer implements serializable {     @column (name="id")     @id     @generatedvalue (strategy=generationtype.auto)     private long id;      @onetoone (cascade=cascadetype.all)     @joincolumn (name="address_id")     private address address;  ... } 

now,the address class given as

public class address implements serializable{ ...    @onetoone (mappedby="address")    private customer customer; } 

is proper?should customer field of address ?that looks strange me.of course makes bidirectional association easy.but,if modelling class called address ,i wouldn't imagine customer field it(my knowledge/experience in oop tiny though).

what guys think?..i know opinion of object oriented design gurus ..

sincerely,

jim

i agree bit odd. that's contrived book examples you, though. it's hard imagine cases want start address , query customers have address.

personally in real-life systems i'd tend discourage making address independent entity own table, , lean toward making address component , including fields on customer. in cases not going manage addresses independently customers (they share same lifecycle), , there less joins , less complications way.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -