I have a software requirement, that needs to store the user that made the last modification to another object, for every object (assume that all objects are already mapped and into a BD).
So we have the ParamBase an object that holds the basic data for every object, this will be a super class, every other parameter in the system will Inherit this class, (Using @MappedSuperClass)
@MappedSuperclass
ParamBase {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Version
private Long version;
@Temporal(value = TemporalType.TIMESTAMP)
private Date timeStampLastModification;
@Column
private User userOfLastModification;
//constructors, getter setters, other stuff, etc
}
The User object, this will represent the user, also mapped into a BD, for now is just simple Object mapped as Entity, all other Parameters will have to store this User into a field.
@Entity
User {
//User stuff, cons, get, seters, etc
}
@Entity
Country extends ParamBase {
//This class extends ParamBase so will have a field to hold the
//userOfLastModification
}
In an EJB I have business logic that will work with several operations and objects, when in this case a parameter is updated, the userSession (assigned at login) will update the userOfLastModification field.
THE PROBLEM: All of the objects will have a relation with User, so all other Objects have a mapped field userOfLastModification_id, this creates a massive dependency of all clases to User. To give you an idea, just picture on an Entity Relation diagram ER, all tables related to one single User Table, it's a mess!!!
THE REFACTOR!: I think this model is wrong, I think breaks the equilibrium of software design I don't think you need to create a relation between all the tables/object to one table (User) to accomplish this requirement, I will like some feedback or ides on how to: 1. Explain the design error, if there is one? (I always think that I can be wrong, and there's no problem with that)
- Is there a better way to do this?
Thanks for your help!