I like to create two java applications with the same user information in my DB, but some user related infos are just relevant for app A, others just for app B.
My question is, can I write the user class for A and ignore the fields for B and vice versa?
Or is the right approach to load fields lazy and leave the fields I’ll never used untouched?
Would that lead to larger objects in memory?
Or would it be better to store information redundantly and update in both tables/dbs if necessary?
Please tell me pros and cons or what could lead to errors.
I use eclipselink and postgres if this matters.
thx @Vikdor but your answer let more questions grow in my head 🙂
-
So the main statement of your answer is, as long as I don’t violate the conditions of the table there is no problem right?
-
Lets say at least one app, maybe both, are heavily used by a large amount of users.
Would it be better to save information redundant to prevent performance issues?
Or is it maybe a good idea to save A/B specific infos in separate object/table with a value that identifies the user like his e-mail, so that I have 3 DBs 1 for A with A-specific data, one for B with B-specific data and one for basic user information (mail, pw, username and so on)?
As long as the applications are going to only read the information from the User table that is relevant to them, it is fine to define the entity with only those attributes that make sense for a given app.
But, if you are going to create new user records through any of these applications, then it is required to define the entity with all the non-nullable attributes of user. Otherwise, the insertions would fail at the database layer.
Regarding the size of objects in the memory, if your user table is quite large and if you don’t use most of the attributes and you only perform read operation, this might be a good optimization to have, to define the user entity with only required attributes.