20 years in other programming languages and now I am new to Java, feeling like an noob programmer...
I use an Indexable
abstract class to extend all of my @entity
classes so I don't need to put the @Id @GeneratedValue @SequenceGenerator
on all of them. And I also have Auditable
with @CreatedBy @CreatedDate @ModifiedBy @ModifiedDate
which leads to those inheritance path:
- MostEntityClasses > AuditableClass > IndexableClass;
- SomeEntityClasses > IndexableClass.
Now I noticed that 99% of my entity classes also have:
@Column(nullable = false, unique = true) private String name;
I thought of moving that line to the Indexable
class to avoid that boilerplate code in those 99%, but the two classes that don't have the name field are important auditable classes and I don't want to just copy all the ancestor fields to them just to prevent errors of null names on it.
The question is: if I override that field's annotations on those two classes to make it nullable and transient, will it work to avoid creating this field on the table and also not bothering the user with null names?
class SomeAuditableClass extends Audited {
//@override
@Column(nullable = true) @Transient private String name;
The content in Is there a way to override class variables in Java? did not helped much...