This is use case for an online movie ticket booking system (like book my show) to book tickets.
Requirements
- There are theaters.
- Theaters have seats.
- A show is played in a theater with a movie.
- Users book seats for show.
- A (Show + Seat) combination should be unique and booked by only one user. (No need to worry about payment failures / rebookings)
The following entities can be created
########################################
Theater
- name: String
- seats: List<Seats>
Seat
- name: String
- theater: Theater
Movie
- name: String
Show
- theater: Theater
- movie: Movie
- startTime: LocalDateTime
- endTime: LocalDateTime
User
- name: String
- email: String
########################################
Booking
- user: User
- bookedShowSeats: List<ShowSeat>
ShowSeat
- show: Show
- seat: Seat
########################################
How should this be modelled in hibernate?
Few questions on this:
- I don't want to create a new entity for
ShowSeat(is this possible using hibernate? To model one-to-many relation without having an entity, I read about @Embeddable but was not able to get it working) - How to model the (Show + Seat) unique constraint?
The below model defines entities
Theater,Seat,Movie,Show,UserandBookingwhereShowSeatis marked with@Embeddableto represent a composite primary key.Remember to configure your Hibernate and JPA configurations.
I hope this helps ✌