@Entity classes in external lib and have the option to override it in the current project

I´m currently working to implement a lib (“Share Project”) for util classes and also some @Entity classes, which I need in all my other projects to avoid duplicate code implementation.

Some @Entity classes I would like to override in my current project (so I can use other properties etc.). Unfortunately inside my “Share Project” I have also in some @Entity classes a reference, like:

@JoinColumn(name = "user_fk", nullable = false)
private User user;

In my current project I want to override than e.g. this User @Entity class, like:

@Table(name = "user", indexes = { @Index(columnList = "user_id, id_hash") })
public class UserCustom implements Serializable {

But my “Share Project” is not aware in the references, that I would like to use my custom User @Entity class.

Here is a visualiation: enter image description here

I would like to need a generic class for “User” e.g. so my “Share project” is searching in my current project for a @Entity “User”. If it´s not found in my project, it will use the @Entity User class from “Share Project”.

Any ideas?

Use a schema management tool like Liquibase or Flyway for managing DDL like indexes.