Неизвестный столбец 'factura0_.id_coche' в 'списке полей' - PullRequest
0 голосов
/ 10 июня 2018

Я пытаюсь найти все "фактуры", у которых есть один "кок".Я установил много отношений, потому что у каждой "фактуры" есть своя "idCoche" в базе данных.Я искал решение этой ошибки, но ни один пост не помог мне.У меня есть следующие объекты:

FACTURA:

@Entity
@Table(name = "factura")
public class Factura implements Serializable {

private static final long serialVersionUID = 1L;


@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Long id;

@Column(name = "nombre")
private String nombre;

@Column(name = "imagenFactura")
private byte[] imagenFactura;

@ManyToOne
@JoinColumn(name="idCoche")
private Coche coche;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getNombre() {
    return nombre;
}

public void setNombre(String nombre) {
    this.nombre = nombre;
}

public byte[] getImagenFactura() {
    return imagenFactura;
}

public void setImagenFactura(byte[] imagenFactura) {
    this.imagenFactura = imagenFactura;
}

public Coche getCoche() {
    return coche;
}

public void setCoche(Coche coche) {
    this.coche = coche;
} 
}

COCHE:

@Entity
@Table(name = "coche")
public class Coche implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "matricula")
private String matricula;

@Column(name = "marca")
private String marca;

@Column(name = "modelo")
private String modelo;

@Column(name = "titular")
private String titular;

@OneToMany(mappedBy="coche")
private List<Factura> facturas;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getMatricula() {
    return matricula;
}

public void setMatricula(String matricula) {
    this.matricula = matricula;
}

public String getMarca() {
    return marca;
}

public void setMarca(String marca) {
    this.marca = marca;
}

public String getModelo() {
    return modelo;
}

public void setModelo(String modelo) {
    this.modelo = modelo;
}

public String getTitular() {
    return titular;
}

public void setTitular(String titular) {
    this.titular = titular;
}

public List<Factura> getFacturas() {
    return facturas;
}

public void setFacturas(List<Factura> facturas) {
    this.facturas = facturas;
}
}

Это мой репозиторий JPA

@Repository
public interface FacturaRepository extends JpaRepository<Factura, Long> {

    List<Factura> findByCocheId(Long id);


}

И, наконец,Это мой ресурс (который генерирует исключение при вызове метода репозитория):

public ResponseEntity<List<Factura>> getAllFacturas(@PathVariable Long id) {
    List<Factura> facturas = facturaRepository.findByCocheId(id);
    return new ResponseEntity<>(facturas, HttpStatus.OK);
}

Спасибо

1 Ответ

0 голосов
/ 10 июня 2018

Изменить отношение в Factura следующим образом:

@ManyToOne
@JoinColumn(name = "id", 
      referencedColumnName = "id")
private Coche coche;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...