java - Should one segregate Domain Objects from Rest of App? -


i'm relatively new hibernate , trying understand best architectural approach designing dao. created set of domain (entity) objects , wrote dao interface , impl access them. reduce risk of using entities in collections wrote equals() , hashcode() methods did not use primary keys. found cumbersome , inefficient. decided eliminate issue confining use of domain objects dao , using dto's send to/retrieve dao. struck me additional benefit abstraction , decoupling of data sent/retrieved table structure.

however, using hibernate can cumbersome if 1 isn't playing entity objects begin with. eg, dao method write list of dependent objects in @onetomany relationship can no longer passed instance of parent-side entity because while code using dao might have parent's id, doesn't have parent entity pass. relationship must either removed or made unidirectional or dao must retrieve of parent entity reference.

one earlier reply labeled dto's anti-pattern. can see why. wider use of entity classes doesn't problem of hibernate identity fields mention become problematic , potentially dangerous? also, there not other advantages abstracting returned data table structures such decoupling? since dto's may needed anyway if complex sets of data returned, why not use them 100% of time , gain advantages mentioned?


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -