我有一个 Spring Boot 应用程序,它有一个非常简单的服务,定义了存储库类,并带有数据库查询。但是当我运行它时出现错误
请查找我收到的以下错误。在启动并运行应用程序时,我在应用程序启动时收到以下错误。插入查询及其尝试插入和读取数据的方式似乎存在问题。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'screeningService' defined in file [C:\wksp\BookMyMovie-master\target\classes\com\sburgula\business\service\ScreeningService.class]:
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'screeningRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property screeningDate found for type String! Traversed path: Screening.movieName.at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1154) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1056) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at com.sburgula.ReservationsApplication.main(ReservationsApplication.java:10) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_321]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_321]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_321]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_321]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.4.3.RELEASE.jar:1.4.3.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'screeningRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property screeningDate found for type String! Traversed path: Screening.movieName.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1589) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1136) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
... 24 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property screeningDate found for type String! Traversed path: Screening.movieName.
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:339) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1585) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
... 35 common frames omitted
这些是我对数据库的插入查询:
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (1234,'Casino');
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (2345,'Sense and Sensibility');
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (5678,'Sabrina');
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (4567,'Heat');
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 1,1,'Casino','2018-05-25','18:00:00', 20);
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 2,1,'Sense and Sensibility','2018-05-24','15:00:00',20);
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 3,1,'Sabrina','2018-05-23','14:00:00', 20);
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 4,1,'Heat','2018-05-22','16:00:00', 20);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 1, 100, 400);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 2, 25, 200);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 3, 50, 200);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 4, 100, 500);
它显示的错误是: 未找到字符串类型的属性筛选日期!遍历的路径:Screening.movieName。 我提供下面的筛选类:
package com.sburgula.data.entity;
import javax.persistence.*;
import java.sql.Date;
import java.sql.Time;
@Entity
@Table(name = "SCREENING")
public class Screening implements Cloneable {
@Id
@Column(name = "SCREENING_ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private long screeningId;
@Column(name = "THEATRE_ID")
private long theatreId;
@Column(name = "SCREEN_ID")
private long screenId;
@Column(name = "MOVIE_NAME")
private String movieName;
@Column(name = "SCREENING_DATE")
private java.sql.Date screeningDate;
@Column(name = "SCREENING_TIME")
private java.sql.Time screeningTime;
@Column(name = "BOOKED_TICKETS")
private int bookedTickets;
public Object clone() throws CloneNotSupportedException{
return super.clone();
}
public int getBookedTickets() {
return bookedTickets;
}
public void setBookedTickets(int bookedTickets) {
this.bookedTickets = bookedTickets;
}
public long getScreeningId() {
return screeningId;
}
public void setScreeningId(long screeningId) {
this.screeningId = screeningId;
}
public long getTheatreId() {
return theatreId;
}
public void setTheatreId(long theatreId) {
this.theatreId = theatreId;
}
public long getScreenId() {
return screenId;
}
public void setScreenId(long screenId) {
this.screenId = screenId;
}
public String getMovieName() {
return movieName;
}
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public Date getScreeningDate() {
return screeningDate;
}
public void setScreeningDate(Date screeningDate) {
this.screeningDate = screeningDate;
}
public Time getScreeningTime() {
return screeningTime;
}
public void setScreeningTime(Time screeningTime) {
this.screeningTime = screeningTime;
}
}
请找到下面的服务类代码:
package com.sburgula.business.service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.sburgula.business.domain.MovieScreening;
import com.sburgula.data.entity.Movie;
import com.sburgula.data.entity.Screening;
import com.sburgula.data.entity.Theatre;
import com.sburgula.data.entity.Ticket;
import com.sburgula.data.repository.MovieRepository;
import com.sburgula.data.repository.ScreenRepository;
import com.sburgula.data.repository.ScreeningRepository;
import com.sburgula.data.repository.TheatreRepository;
import com.sburgula.data.repository.TicketRepository;
@Service
public class ScreeningService {
private ScreeningRepository screeningRepository;
private MovieRepository movieRepository;
private TheatreRepository theatreRepository;
private TicketRepository ticketRepository;
private ScreenRepository screenRepository;
public ScreeningService(ScreeningRepository screeningRepository, MovieRepository movieRepository, TheatreRepository theatreRepository
, TicketRepository ticketRepository, ScreenRepository screenRepository) {
this.screeningRepository = screeningRepository;
this.movieRepository = movieRepository;
this.theatreRepository = theatreRepository;
this.ticketRepository = ticketRepository;
this.screenRepository = screenRepository;
}
private Screening getScreening(MovieScreening movieScreening) {
//Browse theatres currently running the show (movie selected) in the town, including show timing by a chosen date
//Theatre theatre = theatreRepository.findByTheatreNameAndTheatreCity(movieScreening.getTheatreName(), movieScreening.getTheatreCity());
List<Theatre> theatres = theatreRepository.findTheatresByTheatreNameAndTheatreCity(movieScreening.getTheatreName(), movieScreening.getTheatreCity());
if (theatres == null)
return null;
return screeningRepository.findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime(movieScreening.getMovieName(), movieScreening.getTheatreId(),
java.sql.Date.valueOf(movieScreening.getScreeningDate()), java.sql.Time.valueOf(movieScreening.getScreeningTime()));
}
public int bookSeats(MovieScreening movieScreening, int seats) {
//seats -- how many the user wants to book.
Screening screening = getScreening(movieScreening);
//List<Screening> screenings = getScreening(movieScreening);
List<Theatre> theatres = null;
if("PUNE".equalsIgnoreCase(movieScreening.getTheatreCity()) || "HYDERABAD".equalsIgnoreCase(movieScreening.getTheatreCity()) || movieScreening.getTheatreId()==3) {
theatres = theatreRepository.findTheatresByTheatreNameAndTheatreCity(movieScreening.getTheatreCity(), movieScreening.getTheatreName());
}
for(Theatre theatre: theatres) {
if(theatre.getTheatreCity().equals(movieScreening.getTheatreCity())){
List<Ticket> tickets = ticketRepository.findByScreeningId(screening.getScreenId());
for(Ticket ticket : tickets) {
if(ticket.getTicketId() == 3) {
ticket.setPrice(ticket.getPrice().divide(new BigDecimal(2)));
ticketRepository.save(ticket);
}
}
}
screening.setBookedTickets(seats);
screeningRepository.save(screening);
}
return getBookedSeats(movieScreening);
}
public int getBookedSeats(MovieScreening movieScreening) {
Screening screening = getScreening(movieScreening);
return screening.getBookedTickets();
}
public int getTotalSeats(MovieScreening movieScreening) {
Screening screening = getScreening(movieScreening);
long screenId = screening.getScreenId();
return screenRepository.findByScreenId(screenId).getSeatsNum();
}
public Set<Movie> getMoviesByDate(Date date) {
Iterable<Screening> screenings = this.screeningRepository.findByScreeningDate(new java.sql.Date(date.getTime()));
Set<Movie> movies = new HashSet<>();
if (screenings != null) {
for (Screening screening : screenings) {
Movie movie = movieRepository.findByMovieName(screening.getMovieName());
movies.add(movie);
}
}
return movies;
}
public List<Screening> getScreeningsByMovie(String movieName) {
return this.screeningRepository.findByMovieName(movieName);
}
public List<MovieScreening> getMovieScreeningsByMovie(String movieName) {
Iterable<Screening> screenings = this.screeningRepository.findByMovieName(movieName);
List<MovieScreening> movieScreenings = new ArrayList<>();
if (screenings != null) {
for (Screening screening : screenings) {
MovieScreening movieScreening = new MovieScreening();
Theatre theatre = theatreRepository.findByTheatreId(screening.getTheatreId());
movieScreening.setMovieName(screening.getMovieName());
if (theatre != null) {
movieScreening.setTheatreId(theatre.getTheatreId());
movieScreening.setTheatreName(theatre.getTheatreName());
movieScreening.setTheatreCity(theatre.getTheatreCity());
}
movieScreening.setScreeningDate(screening.getScreeningDate().toString());
movieScreening.setScreeningTime(screening.getScreeningTime().toString());
movieScreenings.add(movieScreening);
}
}
return movieScreenings;
}
}
我还添加了存储库类...
@Repository
public interface ScreeningRepository extends CrudRepository<Screening, Long> {
List<Screening> findByScreeningDate(Date screeningDate);
List<Screening> findByMovieName(String movieName);
Screening findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime(String movieName, long theatreId, Date screeningDate, Time screeningTime);
List<Screening> getScreeningsByMovieNameScreeningDateAndScreeningTime(String movieName, Date screeningDate, Time screeningTime);
}
请找到数据加载器类:
package com.sburgula.runner;
import com.sburgula.data.entity.Movie;
import com.sburgula.data.entity.Screen;
import com.sburgula.data.entity.Screening;
import com.sburgula.data.repository.MovieRepository;
import com.sburgula.data.repository.ScreenRepository;
import com.sburgula.data.repository.ScreeningRepository;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
importorg.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import java.io.*;
import java.sql.Date;
import java.sql.Time;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
@Component
public class DataLoader implements ApplicationRunner {
private MovieRepository movieRepository;
private ScreenRepository screenRepository;
private ScreeningRepository screeningRepository;
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
@Autowired
private TaskExecutor taskExecutor;
public MovieRepository getMovieRepository() {
return movieRepository;
}
public ScreeningRepository getScreeningRepository() {
return screeningRepository;
}
public ScreenRepository getScreenRepository() {
return screenRepository;
}
@Autowired
public DataLoader(MovieRepository movieRepository, ScreeningRepository screeningRepository,ScreenRepository screenRepository) {
this.movieRepository = movieRepository;
this.screeningRepository = screeningRepository;
this.screenRepository = screenRepository;
}
private class ProcessMovie implements Runnable {
private String movieLine;
private String linkLine;
ProcessMovie(String movieLine, String linkLine) {
this.movieLine = movieLine;
this.linkLine = linkLine;
}
@Override
public void run() {
LOGGER.info(Thread.currentThread().getId() + ":" + linkLine);
String[] movieInfo = movieLine.split(",");
String movieName = "";
for (int i = 1; i < movieInfo.length-1; i++) {
if (i == movieInfo.length-2)
movieName += movieInfo[i];
else
movieName += movieInfo[i] + ",";
}
Movie movie = new Movie();
movie.setMovieId(Long.parseLong(movieInfo[0]));
movie.setMovieName(movieName.substring(0, movieName.indexOf('(')).trim());
String[] linkInfo = linkLine.split(",");
Document movieLensPage = null;
try {
movieLensPage = Jsoup.connect("https://www.imdb.com/title/tt" + linkInfo[1]).get();
} catch (HttpStatusException e) {
return;
} catch (IOException e) {
e.printStackTrace();
}
movieRepository.save(movie);
}
}
private void populateMovieTable() {
try (BufferedReader brMovies = new BufferedReader(new InputStreamReader(new ClassPathResource("movies.medium.csv").getInputStream()));
BufferedReader brLinks = new BufferedReader(new InputStreamReader(new ClassPathResource("links.csv").getInputStream()))) {
String movieLine;
String linkLine;
brMovies.readLine(); // Skip header line
brLinks.readLine(); // Skip header line
while ((movieLine = brMovies.readLine()) != null{
linkLine = brLinks.readLine();
new ProcessMovie(movieLine, linkLine).run();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void populateScreeningsTable() throws CloneNotSupportedException {
for (int i = 1; i <= 5; i++) {
List<Screen> screens = screenRepository.findByTheatreId(i);
for (int j = 0; j < screens.size(); j++) {
Screening screening1 = new Screening();
Screening screening2 = new Screening();
screening1.setTheatreId(i);
screening1.setScreenId(j+1);
screening2.setTheatreId(i);
screening2.setScreenId(j+1);
long totalMovies = movieRepository.count();
Random random = new Random();
long movieId1 random.nextInt((int)totalMovies)+1;
Movie movie1 = null;
while ((movie1 = movieRepository.findByMovieId(movieId1)) == null)
movieId1 = random.nextInt((int)totalMovies)+1;
long movieId2 = random.nextInt((int)totalMovies)+1;
Movie movie2 = null;
while ((movie2 = movieRepository.findByMovieId(movieId2)) == null)
movieId2 = random.nextInt((int)totalMovies)+1;
screening1.setMovieName(movie1.getMovieName());
screening2.setMovieName(movie2.getMovieName());
Date date1 = new Date((new java.util.Date()).getTime());
Date date2 = new Date(date1.getTime()+3*24*60*60*1000);
Date randomDate1 = new Date(ThreadLocalRandom.current().nextLong(date1.getTime(), date2.getTime()));
Date randomDate2 = new Date(ThreadLocalRandom.current().nextLong(date1.getTime(), date2.getTime()));
screening1.setScreeningDate(randomDate1);
screening2.setScreeningDate(randomDate2);
screening1.setBookedTickets(0);
screening2.setBookedTickets(0);
screening1.setScreeningTime(Time.valueOf("10:00:00"));
screeningRepository.save(screening1);
Screening screening1Clone = (Screening)screening1.clone();
screening1.setScreeningTime(Time.valueOf("18:00:00"));
screeningRepository.save(screening1Clone);
if (randomDate1.getDate() != randomDate2.getDate()) {
screening2.setScreeningTime(Time.valueOf("10:00:00"));
screeningRepository.save(screening2);
Screening screening2Clone = (Screening)screening2.clone();
screening2.setScreeningTime(Time.valueOf("18:00:00"));
screeningRepository.save(screening2Clone);
}
}
}
}
@Override
public void run(ApplicationArguments applicationArguments) throws Exception {
populateMovieTable();
populateScreeningsTable();
}
}
Please find the following error I am receiving.While getting the application up and running I get the following error when app starts up. It seems like there is a problem with the insert queries and how it is trying to insert and read the data.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'screeningService' defined in file [C:\wksp\BookMyMovie-master\target\classes\com\sburgula\business\service\ScreeningService.class]:
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'screeningRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property screeningDate found for type String! Traversed path: Screening.movieName.at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1154) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1056) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]at com.sburgula.ReservationsApplication.main(ReservationsApplication.java:10) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_321]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_321]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_321]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_321]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.4.3.RELEASE.jar:1.4.3.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'screeningRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property screeningDate found for type String! Traversed path: Screening.movieName.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1589) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1136) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
... 24 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property screeningDate found for type String! Traversed path: Screening.movieName.
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:339) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) ~[spring-data-commons-1.12.6.RELEASE.jar:na]
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1585) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
... 35 common frames omitted
These are my insert queries into the DB:
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (1234,'Casino');
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (2345,'Sense and Sensibility');
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (5678,'Sabrina');
INSERT INTO MOVIE (MOVIE_ID,MOVIE_NAME) VALUES (4567,'Heat');
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 1,1,'Casino','2018-05-25','18:00:00', 20);
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 2,1,'Sense and Sensibility','2018-05-24','15:00:00',20);
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 3,1,'Sabrina','2018-05-23','14:00:00', 20);
INSERT INTO SCREENING (SCREENING_ID, THEATRE_ID, SCREEN_ID, MOVIE_NAME,SCREENING_DATE,SCREENING_TIME,BOOKED_TICKETS) VALUES (DEFAULT, 4,1,'Heat','2018-05-22','16:00:00', 20);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 1, 100, 400);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 2, 25, 200);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 3, 50, 200);
INSERT INTO TICKET (TICKET_ID, SCREENING_ID, SEAT_NUM, PRICE) VALUES (DEFAULT, 4, 100, 500);
The error it shows is:
No property screeningDate found for type String! Traversed path: Screening.movieName.
I am giving the Screening class below:
package com.sburgula.data.entity;
import javax.persistence.*;
import java.sql.Date;
import java.sql.Time;
@Entity
@Table(name = "SCREENING")
public class Screening implements Cloneable {
@Id
@Column(name = "SCREENING_ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private long screeningId;
@Column(name = "THEATRE_ID")
private long theatreId;
@Column(name = "SCREEN_ID")
private long screenId;
@Column(name = "MOVIE_NAME")
private String movieName;
@Column(name = "SCREENING_DATE")
private java.sql.Date screeningDate;
@Column(name = "SCREENING_TIME")
private java.sql.Time screeningTime;
@Column(name = "BOOKED_TICKETS")
private int bookedTickets;
public Object clone() throws CloneNotSupportedException{
return super.clone();
}
public int getBookedTickets() {
return bookedTickets;
}
public void setBookedTickets(int bookedTickets) {
this.bookedTickets = bookedTickets;
}
public long getScreeningId() {
return screeningId;
}
public void setScreeningId(long screeningId) {
this.screeningId = screeningId;
}
public long getTheatreId() {
return theatreId;
}
public void setTheatreId(long theatreId) {
this.theatreId = theatreId;
}
public long getScreenId() {
return screenId;
}
public void setScreenId(long screenId) {
this.screenId = screenId;
}
public String getMovieName() {
return movieName;
}
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public Date getScreeningDate() {
return screeningDate;
}
public void setScreeningDate(Date screeningDate) {
this.screeningDate = screeningDate;
}
public Time getScreeningTime() {
return screeningTime;
}
public void setScreeningTime(Time screeningTime) {
this.screeningTime = screeningTime;
}
}
Please find the code for service class below:
package com.sburgula.business.service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.sburgula.business.domain.MovieScreening;
import com.sburgula.data.entity.Movie;
import com.sburgula.data.entity.Screening;
import com.sburgula.data.entity.Theatre;
import com.sburgula.data.entity.Ticket;
import com.sburgula.data.repository.MovieRepository;
import com.sburgula.data.repository.ScreenRepository;
import com.sburgula.data.repository.ScreeningRepository;
import com.sburgula.data.repository.TheatreRepository;
import com.sburgula.data.repository.TicketRepository;
@Service
public class ScreeningService {
private ScreeningRepository screeningRepository;
private MovieRepository movieRepository;
private TheatreRepository theatreRepository;
private TicketRepository ticketRepository;
private ScreenRepository screenRepository;
public ScreeningService(ScreeningRepository screeningRepository, MovieRepository movieRepository, TheatreRepository theatreRepository
, TicketRepository ticketRepository, ScreenRepository screenRepository) {
this.screeningRepository = screeningRepository;
this.movieRepository = movieRepository;
this.theatreRepository = theatreRepository;
this.ticketRepository = ticketRepository;
this.screenRepository = screenRepository;
}
private Screening getScreening(MovieScreening movieScreening) {
//Browse theatres currently running the show (movie selected) in the town, including show timing by a chosen date
//Theatre theatre = theatreRepository.findByTheatreNameAndTheatreCity(movieScreening.getTheatreName(), movieScreening.getTheatreCity());
List<Theatre> theatres = theatreRepository.findTheatresByTheatreNameAndTheatreCity(movieScreening.getTheatreName(), movieScreening.getTheatreCity());
if (theatres == null)
return null;
return screeningRepository.findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime(movieScreening.getMovieName(), movieScreening.getTheatreId(),
java.sql.Date.valueOf(movieScreening.getScreeningDate()), java.sql.Time.valueOf(movieScreening.getScreeningTime()));
}
public int bookSeats(MovieScreening movieScreening, int seats) {
//seats -- how many the user wants to book.
Screening screening = getScreening(movieScreening);
//List<Screening> screenings = getScreening(movieScreening);
List<Theatre> theatres = null;
if("PUNE".equalsIgnoreCase(movieScreening.getTheatreCity()) || "HYDERABAD".equalsIgnoreCase(movieScreening.getTheatreCity()) || movieScreening.getTheatreId()==3) {
theatres = theatreRepository.findTheatresByTheatreNameAndTheatreCity(movieScreening.getTheatreCity(), movieScreening.getTheatreName());
}
for(Theatre theatre: theatres) {
if(theatre.getTheatreCity().equals(movieScreening.getTheatreCity())){
List<Ticket> tickets = ticketRepository.findByScreeningId(screening.getScreenId());
for(Ticket ticket : tickets) {
if(ticket.getTicketId() == 3) {
ticket.setPrice(ticket.getPrice().divide(new BigDecimal(2)));
ticketRepository.save(ticket);
}
}
}
screening.setBookedTickets(seats);
screeningRepository.save(screening);
}
return getBookedSeats(movieScreening);
}
public int getBookedSeats(MovieScreening movieScreening) {
Screening screening = getScreening(movieScreening);
return screening.getBookedTickets();
}
public int getTotalSeats(MovieScreening movieScreening) {
Screening screening = getScreening(movieScreening);
long screenId = screening.getScreenId();
return screenRepository.findByScreenId(screenId).getSeatsNum();
}
public Set<Movie> getMoviesByDate(Date date) {
Iterable<Screening> screenings = this.screeningRepository.findByScreeningDate(new java.sql.Date(date.getTime()));
Set<Movie> movies = new HashSet<>();
if (screenings != null) {
for (Screening screening : screenings) {
Movie movie = movieRepository.findByMovieName(screening.getMovieName());
movies.add(movie);
}
}
return movies;
}
public List<Screening> getScreeningsByMovie(String movieName) {
return this.screeningRepository.findByMovieName(movieName);
}
public List<MovieScreening> getMovieScreeningsByMovie(String movieName) {
Iterable<Screening> screenings = this.screeningRepository.findByMovieName(movieName);
List<MovieScreening> movieScreenings = new ArrayList<>();
if (screenings != null) {
for (Screening screening : screenings) {
MovieScreening movieScreening = new MovieScreening();
Theatre theatre = theatreRepository.findByTheatreId(screening.getTheatreId());
movieScreening.setMovieName(screening.getMovieName());
if (theatre != null) {
movieScreening.setTheatreId(theatre.getTheatreId());
movieScreening.setTheatreName(theatre.getTheatreName());
movieScreening.setTheatreCity(theatre.getTheatreCity());
}
movieScreening.setScreeningDate(screening.getScreeningDate().toString());
movieScreening.setScreeningTime(screening.getScreeningTime().toString());
movieScreenings.add(movieScreening);
}
}
return movieScreenings;
}
}
I am addign the Repository class as well...
@Repository
public interface ScreeningRepository extends CrudRepository<Screening, Long> {
List<Screening> findByScreeningDate(Date screeningDate);
List<Screening> findByMovieName(String movieName);
Screening findByMovieNameAndTheatreIdAndScreeningDateAndScreeningTime(String movieName, long theatreId, Date screeningDate, Time screeningTime);
List<Screening> getScreeningsByMovieNameScreeningDateAndScreeningTime(String movieName, Date screeningDate, Time screeningTime);
}
Please find the Data Loader Class:
package com.sburgula.runner;
import com.sburgula.data.entity.Movie;
import com.sburgula.data.entity.Screen;
import com.sburgula.data.entity.Screening;
import com.sburgula.data.repository.MovieRepository;
import com.sburgula.data.repository.ScreenRepository;
import com.sburgula.data.repository.ScreeningRepository;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
importorg.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import java.io.*;
import java.sql.Date;
import java.sql.Time;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
@Component
public class DataLoader implements ApplicationRunner {
private MovieRepository movieRepository;
private ScreenRepository screenRepository;
private ScreeningRepository screeningRepository;
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
@Autowired
private TaskExecutor taskExecutor;
public MovieRepository getMovieRepository() {
return movieRepository;
}
public ScreeningRepository getScreeningRepository() {
return screeningRepository;
}
public ScreenRepository getScreenRepository() {
return screenRepository;
}
@Autowired
public DataLoader(MovieRepository movieRepository, ScreeningRepository screeningRepository,ScreenRepository screenRepository) {
this.movieRepository = movieRepository;
this.screeningRepository = screeningRepository;
this.screenRepository = screenRepository;
}
private class ProcessMovie implements Runnable {
private String movieLine;
private String linkLine;
ProcessMovie(String movieLine, String linkLine) {
this.movieLine = movieLine;
this.linkLine = linkLine;
}
@Override
public void run() {
LOGGER.info(Thread.currentThread().getId() + ":" + linkLine);
String[] movieInfo = movieLine.split(",");
String movieName = "";
for (int i = 1; i < movieInfo.length-1; i++) {
if (i == movieInfo.length-2)
movieName += movieInfo[i];
else
movieName += movieInfo[i] + ",";
}
Movie movie = new Movie();
movie.setMovieId(Long.parseLong(movieInfo[0]));
movie.setMovieName(movieName.substring(0, movieName.indexOf('(')).trim());
String[] linkInfo = linkLine.split(",");
Document movieLensPage = null;
try {
movieLensPage = Jsoup.connect("https://www.imdb.com/title/tt" + linkInfo[1]).get();
} catch (HttpStatusException e) {
return;
} catch (IOException e) {
e.printStackTrace();
}
movieRepository.save(movie);
}
}
private void populateMovieTable() {
try (BufferedReader brMovies = new BufferedReader(new InputStreamReader(new ClassPathResource("movies.medium.csv").getInputStream()));
BufferedReader brLinks = new BufferedReader(new InputStreamReader(new ClassPathResource("links.csv").getInputStream()))) {
String movieLine;
String linkLine;
brMovies.readLine(); // Skip header line
brLinks.readLine(); // Skip header line
while ((movieLine = brMovies.readLine()) != null{
linkLine = brLinks.readLine();
new ProcessMovie(movieLine, linkLine).run();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void populateScreeningsTable() throws CloneNotSupportedException {
for (int i = 1; i <= 5; i++) {
List<Screen> screens = screenRepository.findByTheatreId(i);
for (int j = 0; j < screens.size(); j++) {
Screening screening1 = new Screening();
Screening screening2 = new Screening();
screening1.setTheatreId(i);
screening1.setScreenId(j+1);
screening2.setTheatreId(i);
screening2.setScreenId(j+1);
long totalMovies = movieRepository.count();
Random random = new Random();
long movieId1 random.nextInt((int)totalMovies)+1;
Movie movie1 = null;
while ((movie1 = movieRepository.findByMovieId(movieId1)) == null)
movieId1 = random.nextInt((int)totalMovies)+1;
long movieId2 = random.nextInt((int)totalMovies)+1;
Movie movie2 = null;
while ((movie2 = movieRepository.findByMovieId(movieId2)) == null)
movieId2 = random.nextInt((int)totalMovies)+1;
screening1.setMovieName(movie1.getMovieName());
screening2.setMovieName(movie2.getMovieName());
Date date1 = new Date((new java.util.Date()).getTime());
Date date2 = new Date(date1.getTime()+3*24*60*60*1000);
Date randomDate1 = new Date(ThreadLocalRandom.current().nextLong(date1.getTime(), date2.getTime()));
Date randomDate2 = new Date(ThreadLocalRandom.current().nextLong(date1.getTime(), date2.getTime()));
screening1.setScreeningDate(randomDate1);
screening2.setScreeningDate(randomDate2);
screening1.setBookedTickets(0);
screening2.setBookedTickets(0);
screening1.setScreeningTime(Time.valueOf("10:00:00"));
screeningRepository.save(screening1);
Screening screening1Clone = (Screening)screening1.clone();
screening1.setScreeningTime(Time.valueOf("18:00:00"));
screeningRepository.save(screening1Clone);
if (randomDate1.getDate() != randomDate2.getDate()) {
screening2.setScreeningTime(Time.valueOf("10:00:00"));
screeningRepository.save(screening2);
Screening screening2Clone = (Screening)screening2.clone();
screening2.setScreeningTime(Time.valueOf("18:00:00"));
screeningRepository.save(screening2Clone);
}
}
}
}
@Override
public void run(ApplicationArguments applicationArguments) throws Exception {
populateMovieTable();
populateScreeningsTable();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在您的存储库中。您最后的
getScreeningsByMovieNameScreeningDateAndScreeningTime
是错误的。应该是的。当您编写复杂查询时,我建议编写 SQL 本机或非本机查询。 更多
The problem is in your repository. Your last
getScreeningsByMovieNameScreeningDateAndScreeningTime
is wrong. It should be.When you write complex queries I recommend writing SQL native or non native queries. More