1

I have the following requirement:

Modify the Spring boot application MovieMax of Exercise 1 to use Spring Data JPA so that the data is persisted in the MySQL DB.

Fetch the theater details from theater table and movie details from movie table.

Booking a movie should update corresponding details in theatermovieshow table and booking table

The following script can be used for creation of the tables:

create table user(userid varchar(8) primary key, username varchar(25), password varchar(10), emailid varchar(30), phone int);

create table theater(theaterid varchar(8) primary key, theatername varchar(30), seatsavailable int(3), city varchar(25));

create table movie(movieid varchar(8) primary key, moviename varchar(40), language varchar(15), category varchar(20), islive boolean);

create table theatermovieshow( showid varchar(8) primary key,

theaterid varchar(8) references theater(theaterid),

movieid varchar(8) references movie(movieid),

showtime varchar(8),

startdate date,

enddate date,

ticketrate double(6,2));

create table booking(bookingid int(5), userid varchar(8) references user(userid),

showid varchar(8) references theatermovieshow(showid),

noofseats int,

amountpaid double(8,2),

showdate date,

bookingdate date);

Verification:

On execution, the required details should be fetched from database.

Verify that booking details are getting persisted in corresponding tables.

Do I need to write entity classes for each and every table? I am using spring Boot

Surya Teja
  • 11
  • 2

1 Answers1

1

You don't need to create classes for every table. You can use native query. Quoting answer from https://stackoverflow.com/a/50956683/1039555 :-

Create a method in the repository class with specific query (native query):

@Query(value="select * from emp", nativeQuery=true)
Object getAllFromEmp();

Keep this method in the repository interface and call it from the service class

Or you can use EntityManager object as below

Query q = entityManager.createNativeQuery("SELECT * FROM emp e");
List<Object[]> empObject= q.getResultList();

For updates, use a method like executeUpdate().

Kartik
  • 7,677
  • 4
  • 28
  • 50