Maurice
Maurice

Reputation: 7381

using inheritance in hibernate to copy object from a subclass table to a superclass table

I am making a website that allows users to add records to a database. Before the record is added the submitted record needs to be approved by a moderator first before it is allowed in the actual record table. I want to make use of 2 recordObjects to achieve this. One being a subclass of the other and inheriting all its columns and properties.

So pendingRecord extends Record. The pendingRecord submission goes into the pendingRecord table first (which is identical in columns to the Record table) and when it is approved by a moderator the pendingRecord row gets added in the Record table and removed from the pendingRecord table.

Does anyone know how I can achieve this? I have already looked at using @Inheritance and @Mappedsuperclass annotations but none of them seem to give me the solution I need.

Kind regards,

Upvotes: 0

Views: 56

Answers (1)

oopexpert
oopexpert

Reputation: 755

So far as I see you do not follow semantics:

You have one record that contains unapproved data. The other record is about approved data. So even if you tend to see redundancy it's not. Therefore inheritance is wrong.

If you have the record approved or declined in the whole you may come up with a "state"-field containing the artefact to identify if a record was aaproved or declined.

One way or the other inheritance is not appropriate in your situation.

Only reusing datastructures because they look similar may lead to error type II. You think you make your code better but in reality you will make it even worse. In this case you want to abstract from something where there is no appropriate abstraction.

Think about this: An offer and an order my contain similar information but they have totally different semantics. There is no such abstraction over offer and order that contains the overlapping fields. They are totally separated datastructures.

Upvotes: 1

Related Questions