• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

hibernate : data layer separate from object layer  RSS feed

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: 630
  • 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: 20562
Android Eclipse IDE 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.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!