1

I have a scenario where i have the same table columns but with different names like TicketBooking and TicketBookingHistory. I have a single pojo class TicketBooking. Is it possible to provide more than one mapping for this persistent class that is one for TicketBooking and one for TicketBookingHistory ? If so how to do it ?

Thanks

Srikanth Sridhar
  • 2,317
  • 7
  • 30
  • 50

3 Answers3

1

It is possible with xml mappings. Nno way to achieve this with annotations.

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
1
<class name="TicketBooking" table="TicketBooking"
        entity-name="TicketBooking">

</class>

<class name="TicketBooking" table="TicketBookingHistory"
        entity-name="TicketBookingHistory">
    ...
</class>

This feature is not supported in Annotations.

I think your should have look in Mapping a class more than once. The same question can be found in Map Two Identical tables ( same schema...) to same entity in Hibernate.

But all of these are used with xml mapping.

Community
  • 1
  • 1
swemon
  • 5,840
  • 4
  • 32
  • 54
0

You can do this with entity-name attribute of class mapping. Check the documentation here of the same.

To quote the documentation:

entity-name (optional - defaults to the class name): Hibernate3 allows a class to be mapped 
multiple times, potentially to different tables

Here is another example of the same use case.

Santosh
  • 17,667
  • 4
  • 54
  • 79