You may found useful hibernate inheritance features:
https://marcin-chwedczuk.github.io/mapping-inheritance-in-hibernate
So it is possible to create the abstract entity which contains id and common fields:
@MappedSuperclass
public abstract class Ticket {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
...
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
And implemenations for different tables:
@Entity
@Table(name = "st_ticket1")
public class Ticket1 extends Ticket {
}
@Entity
@Table(name = "st_ticket2")
public class Ticket2 extends Ticket {
}
Than read implementation instances from a DB and cast them to Ticket abstraction to use it for business logic.