• 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

hibernate : data layer separate from object layer

Ranch Hand
Posts: 105
  • 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: 632
  • 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.
Posts: 21000
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.
money grubbing section goes here:
create, convert, edit or print DOC and DOCX in Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!