I would like to understand the reason why, in the compiled java file, there are so complete informations about the .java file (non-compiled) Hibernate's annotations.
For security reasons, my development team is concerned about what goes inside the .class file. We have noticed that after compiling an entity class, the .class file generated contains all the information about the entity annotations from the original .java file.
Since hibernate has evolved, it was offered to the users to substitute the xml centralized file by annotations in the entity classes.
It may sound obvious for some that if an object have all the necessary information about its own mapping to a table, it is the guy that is responsible for handle that relationship. But that understanding shouldn't be so obvious.
To make possible to users to annotate in class files is an strategy to facilitate the development process and not necessarily has to mirror the lower level implementation.
If the xml generates an central object (or a set of it) that deals with the relationship between the java objects and their related database tables, this approach doesn't need necessarilly to be changed because of the annotation advent. Maybe in the compilation or even in the execution time, the annotations provided by the entity classes could be used to compound that centralized object built by the xml. So the centralized approach could be what is being used even when you choose to annotate a class.
The point I would like to make clear is why that information is in the compiled (.class) file. Is it because each entity has to handle is own mapping or is it for some other reason? Can the file be compiled withou the annotation information? if so, the code will still work?
|