Issue
i've been writing wirting a program in Spring Boot Web with JPA and i'm using a query to access some data with a 'contains' and 'ignorecase' filter, i've done this before in other programs and it has worked fine, but now i'm getting this error, i'm completely lost at this point since i can't find anything in google, i went really far down the rabbit hole looking as to why it happens and so far i don't see anything out of place in my code, the type of variable declared seems to be okay but as i've said, i'm lost. It's important to mention that for some reason when I do the query on my website for the first time, everything works fine, i get the proper results and all, but when I go back to home and try with another query (or even the same) i get the error. Code below:
Model
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Serie {
@Id
@Column(columnDefinition = "NUMERIC(19,0)")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String title;
private String red;
@Column(columnDefinition = "NUMERIC(19,0)")
private double rating;
Repository
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import cl.desafiolatam.imdb.modelo.Serie;
public interface SerieRepository extends JpaRepository<Serie, Integer> {
public List<Serie> findByTitleContainingIgnoreCase(String title);
}
Service
import cl.desafiolatam.imdb.vo.SerieVO;
public interface SerieService {
public SerieVO findByTitleContainingIgnoreCase(String title);
}
Service implementation
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cl.desafiolatam.imdb.dao.SerieRepository;
import cl.desafiolatam.imdb.modelo.Serie;
import cl.desafiolatam.imdb.service.SerieService;
import cl.desafiolatam.imdb.vo.SerieVO;
@Service
public class SerieServiceImpl implements SerieService {
private static final Logger logger = LoggerFactory.getLogger(SerieServiceImpl.class);
@Autowired
SerieRepository dao;
SerieVO respuesta;
@Override
@Transactional(readOnly = true)
public SerieVO findByTitleContainingIgnoreCase(String title) {
respuesta = new SerieVO("Ha ocurrido un error!", "104", new ArrayList<Serie>());
try {
List<Serie> serie = dao.findByTitleContainingIgnoreCase(title);
System.out.println(serie);
if(serie.size() > 0) {
respuesta.setSeries(serie);
respuesta.setMensaje("Se ha encontrado el registro");
respuesta.setCodigo("0");
} else {
respuesta.setMensaje("No se ha encontrado el registro");
respuesta.setCodigo("104");
}
} catch (Exception e) {
logger.error("Error al buscar la serie", e);
}
return respuesta;
}
}
Visual object
import java.util.List;
import cl.desafiolatam.imdb.modelo.Serie;
public class SerieVO extends GenericVO {
List<Serie> series;
public SerieVO(String mensaje, String codigo, List<Serie> series) {
super(mensaje, codigo);
this.series = series;
}
public SerieVO() {
super();
}
Controller
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import cl.desafiolatam.imdb.modelo.Serie;
import cl.desafiolatam.imdb.service.SerieService;
import cl.desafiolatam.imdb.vo.SerieVO;
@Controller
public class SerieController {
private final static Logger logger = LoggerFactory.getLogger(SerieController.class);
@Autowired
private SerieService svc;
@GetMapping("/buscarSerie")
public ModelAndView buscarSerie(Model model, @RequestParam String nombreSerie) {
SerieVO respuestaServicio = new SerieVO();
respuestaServicio.setMensaje("No se ha encontrado la serie");
try {
respuestaServicio = svc.findByTitleContainingIgnoreCase(nombreSerie);
model.addAttribute("listaSeries", respuestaServicio.getSeries());
return new ModelAndView("resultadoserie");
} catch (Exception e) {
logger.error("Error al buscar la serie", e);
}
return new ModelAndView("redirect:/user");
}
}
Search input
<div class="d-flex justify-content-center pb-2">
<div class="container row">
<div class="col-md-4">
<div class="d-flex justify-content-center">
<h2>Buscar serie</h2>
</div>
</div>
<div class="col-md-8">
<form action="buscarSerie" method="get">
<div class="row g-2">
<div class="col-md">
<div class="form-floating">
<input type="text" class="form-control" id="floatingInputGrid"
value="" name="nombreSerie" required> <label
for="floatingInputGrid">Serie</label>
</div>
</div>
</div>
<div class="d-flex justify-content-center pt-4">
<input type="submit" class="btn m-2 btn-dark" value="Buscar" />
</div>
</form>
</div>
</div>
</div>
As i've said, im really lost, researched everywhere, and checked the code in my last projects, i just can't find out why this one does me this dirty. Won't even fail at the start, it gives me a glimpse of hope and when i want to retry it, it crushes that little hope. :)
I tried deleting my code and copy&paste from projects where i know it works as intended, changed the variable and param. names to make it work with the new program but didn't work. Did a side by side comparison, tried a @Query writing the specific instruction. Looking for info. only with the 'contains' filter and yet, nothing worked.
Solution
According to the Spring Data JPA issue #2472 this seems to be a problem in Hibernate 5.6.6 and 5.6.7.
The Hibernate bug is HHH-15142.
The solution is to either downgrade to Hibernate 5.6.5 or wait for a Hibernate patch to solve this issue.
Answered By - Koraktor
Answer Checked By - Marie Seifert (JavaFixing Admin)