1.

What are the drawbacks of using Hibernate Annotations?

Answer»

Using Hibernate Annotations has the following drawbacks: 

  • Annotations are inclusive in the code and any changes made to the Annotations leads to code recompilation whereas an XML mapping file is placed outside the code file. So changes can be made without recompilation 
  • If migrating from a legacy environment like Hibernate 2 or Hibernate 3, the pre-existing POJO source code need not be altered due to it using XML mapping and WORKING well which means you will not inject known good code with possible bugs. 
  • Using Annotations does not separate behavior and the POJO class. All information is in a single file. 
  • Some annotations can cause lifecycle mismatches and should be avoided. 
  • Some examples of bad annotations are ORM mapping, DATABASE configuration, hard CODED config for items that may vary between deployment environments, validations that may vary depending on context. 

Let us look at a simple scenario. As we know every bit of data, be it source code, a compiled class, an OBJECT or anything has a lifecycle associated with it. Suppose we add Hibernate Annotations to our Java code especially if we are connecting to a database and are expecting only this class to connect to the database. The table columns are mapped to the class using the annotations. Now let us assume that we use this class in an API and have consumed the API in a different project. Now the annotations we had used will leak into our API causing mismatches as the database and the tables are different. So, we end up using mapping tools to translate between different layers of the beans in a system. This is an example of the DISADVANTAGES of using annotations. 



Discussion

No Comment Found