URL-адрес API не работает, я заметил, что данные заполняются только в БД. Я использую Spring Boot в домашней базе данных H2.
------ ПРИМЕР КЛАССА------
Код: Выделить всё
@Entity
public class sample {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String teamName;
private long totalMatches;
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
public long getTotalMatches() {
return totalMatches;
}
public void setTotalMatches(long totalMatches) {
this.totalMatches = totalMatches;
}
public sample(String teamName, long totalMatches) {
this.teamName = teamName;
this.totalMatches = totalMatches;
}
public sample() {
}
@Override
public String toString() {
return "Team [teamName=" + teamName + ", totalMatches=" + totalMatches;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Код: Выделить всё
@Component
public class JobCompletionNotificationListener implements JobExecutionListener {
private static final Logger log = LoggerFactory.getLogger(JobCompletionNotificationListener.class);
private final EntityManager em;
public JobCompletionNotificationListener(EntityManager em) {
this.em = em;
}
@Override
@Transactional
public void afterJob(JobExecution jobExecution) {
if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
log.info("!!! JOB FINISHED! Time to verify the results");
sample sampleD = new sample("abc", 20);
if (em.contains(sampleD)) {
log.info("----Present----");
} else {
em.persist(sampleD);
}
System.out.println(sampleD);
}
}
}
if (em.contains(sampleD)) {
log.info("----Present----");
Я не могу понять, пока данные печатаются в консоли, почему данные не вставляются в DB.
Нужна помощь по тому же вопросу, я что-то упускаю?
Заранее спасибо!
Подробнее здесь: https://stackoverflow.com/questions/786 ... nsole-upon