Femgineer

Feather Weight Hibernate Objects

In my previous post Cheap Tricks to Fullfill Your Need for Speed, I talked about how you could reduce the memory footprint of your data base query by using a SQL query instead of a Hibernate query, and retrieve only the columns that are you need. However, there maybe times when you actually want to use a pojo, and retrieving columns and storing them in an object array is insufficient. One solution is to create a feather weight Hibernate object. A feather weight Hibernate object contains a subset of the original Hibernate object’s properties (i.e. a limited set of the data base columns), based on which properties you specify. You still map to the same data base table, but your Hibernate mapping file contains fewer columns, therefore while querying you retrieve data from fewer columns thereby speeding up your query. You can continue to use Hibernate objects as pojos by retrieving the Hibernate through a criteria query or HQL statements.

Another reason to do use feather weight objects is when creating data base tables to store data from third party vendors. In many cases the vendors provide you with a lot of data fields, which you will want to store in the table because your data needs might change based on your feature set. But you might not need to retrieve all the fields for the current feature set. Using feature weight Hibernate objects allows you to continue storing all the fields, but only retrieve those that are the most essential.


Exit mobile version