2017-09-20 3 views
0

Je pense que l'erreur est une exception de type missmatch, mais je ne sais pas pourquoi je l'obtiens.Spring Erreur de requête de mise à jour de données

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'carController' defined in file [C:\Users\aleks\Desktop\Spring Boot With Rest\app\target\classes\carMarket\app\controllers\CarController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'carServiceImpl' defined in file [C:\Users\aleks\Desktop\Spring Boot With Rest\app\target\classes\carMarket\app\services\implementations\CarServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract carMarket.app.orm.Car carMarket.app.repositories.CarRepository.updateCar(java.lang.String,java.lang.String,java.lang.Long,java.math.BigDecimal)! 

Ce service je l'appelle avec

@Transactional 
@Override 
public boolean editCar(long userId, long carId, CarBindingModel carBindingModel) 
{ 
    Car car = this.carRepository.findById(carId); 
    Car map = this.modelMapper.map(carBindingModel, Car.class); 
    String make = carBindingModel.getMake(); 
    String model = carBindingModel.getModel(); 
    Long milesDriven = carBindingModel.getMilesDriven(); 
    BigDecimal price = carBindingModel.getPrice(); 
    Car car1 = this.carRepository.updateCar(make, model, milesDriven, price); 
    return false; 
} 

Et c'est le ORM

@Entity(name = "cars") 
public class Car 
{ 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 
    @NotNull 
    private String make; 
    @NotNull 
    private String model; 
    @NotNull 
    private BigDecimal price; 
    @NotNull 
    private Long milesDriven; 
    @JoinColumn(name = "user_id", referencedColumnName = "id") 
    @OneToOne(fetch = FetchType.EAGER) 
    private User user; 

Bien sûr, il a getters publics et setters et un constructeur public vide. Cette erreur accures que dans la méthode de mise à jour, je n'ai aucun problème avec la méthode de suppression ou trouver ..

C'est la requête elle-même

@Modifying 
@Query(value = "UPDATE Car as s set s.make= :make, s.model= :model, s.milesDriven= :milesDriven, s.price= :price") 
Car updateCar(@Param(value = "make") String make, @Param(value = "model") String model, @Param(value = "milesDriven") Long milesDriven, @Param(value = "price") BigDecimal price); 

BTW ceci est erreur de compilation de temps.

+0

ajouter la méthode updateCar –

Répondre

0

Donc, mon problème était le vide sanitaire J'ai eu ce

@Entity(name = "cars") 
public class Car 

Et puis dans le JPQL ci-dessus la méthode des dépôts i eu cette

@Query(value = "UPDATE Car as s set s.make= :make, s.model= :model, s.milesDriven= :milesDriven, s.price= :price") 

Il ne doit pas avoir été UPDATE Car, mais UPDATE cars