1

There are similar table in my database st_tickets_1, st_tickets_2, st_tickets_3 and so on that can be generated as per need. I want to map these table with the single Entity. But I can not map because I have to put the static table name over entity @Table("st_tickets_1").

for as of now i am doing using Spring JDBC templet.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.