Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

hibernate : data layer separate from object layer

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have been diving into hibernate lately, and am enjoying it, but am wondering if anyone has come across this particular use case. If you have lots of classes like Cat, Dog, Parakeet, etc. and you have them organized with abstract classes and interfaces, is it considered bad form to create an object such as





Then in your DogDAO you would build an AnimalEntity and save it. I think this could simplify the data layer, and add for more search  fluidity.
This seems simpler to me, but I have not come across anyone recommending that particular design. Is it widely used?

 
Ranch Hand
Posts: 635
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , have a seperate entity for each object you are saving. I would have PersonPOJO map to a PersonEntity, and save that enity in a personRepository which would have my hibernate or JPA functionality.
Also think of caching, if you are going to cashe in hibernate second level. It would be as an entity.
 
Saloon Keeper
Posts: 22097
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate JPA, and for that matter, JPA in general, work quite well with Java inheritance. You could have a base class for animals, and separate subclasses for cats, dogs, and so forth. In such a case, each subclass would have a corresponding database table.

Alternatively, you might have a common database table and create database Views and map the CAT view to the Cat entity type, the DOG view to the Dog entity type, and so forth.

There are all sorts of fun games you can play that way.
 
Space pants. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic