Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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: 10662
144
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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic