• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement light weight version of an entity using hibernate annotations?

 
Rajasekhar Karanam
Greenhorn
Posts: 16
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In our project, we have an entity 'Restaurant' with nearly 30 fields(some have relationships with other entities). So, every time we need a 'Restaurant' object even for a few fields, all the others are retrieved. This effects the performance. So, in the hbm file we wrote two classes both pointing to the same physical class and same table in database as shown below.



In one of the DAO implementations, we are using Criteria which takes 'RestaurantLite' and returning list of restaurants as we have to work with only restaurant objects as shown below.



Now we want to remove all hbm files and use annotations. So how the same can be done using annotations for entites? Do we need to create an extra class 'RestaurantLite'? If then, how the above criteria returns 'Restaurant' objects??
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most straightforward way to do this is to map properties you don't use often as lazy:Hibernate would not load such properties initially; instead they'll be loaded on demand (when first accessed).

Did you already consider this approach?
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!