Rule Definition
One main source of data corruption within applications comes from lack of compliance to data modification rules defined for an application. These rules are usually related to the use of specific procedures for update/insert/delete, a specific API or a data layer that is fully tested to maintain data integrity. The creation of new, different update/insert/delete procedures and functions that do not make use the existing tested code is at origin of many data corruption cases.
In the case of Hibernate, having different mapping files associated with the same table is a source of such data corruption.
Remediation
Review your design and decide which Entity must manage the table.
Violation Code Sample
// VIOLATION: table A is referenced by two Entities
---> a.hbm.xml
<class name="A" table="A">
...
</class>
---> b.hbm.xml
<class name="B" table="A">
...
</class>
Fixed Code Sample
create table Contact ( id integer not null, first varchar(255), last varchar(255), middle varchar(255), notes varchar(255), starred boolean not null, website varchar(255), primary key (id) ) @Entity(name = "Contact") //FIXED:Single class should be associated to a table. public static class Contact { @Id private Integer id; private Name name; private String notes; private URL website; private boolean starred; //Getters and setters are omitted for brevity }
Reference
https://docs.jboss.org/hibernate/stable/orm/userguide/html_single/Hibernate_User_Guide.html#entity
Related Technologies
JEE
Technical Criterion
Architecture - Multi-Layers and Data Access
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.