2

I have a bidirectional one-to-many relation between this entities, all of this was created by the JPA wizard of Netbeans

Vehiculo (Vehicle)

@Entity
@Table(name = "vehiculo")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Vehiculo.findAll", query = "SELECT v FROM Vehiculo v"),
@NamedQuery(name = "Vehiculo.findById", query = "SELECT v FROM Vehiculo v WHERE v.id =    :id")})
public class Vehiculo implements Serializable {

  //more attributes

  @OneToMany(cascade = CascadeType.ALL, mappedBy = "idVehiculo", fetch =  FetchType.LAZY)
  private List<PuntoTrayecto> puntoTrayectoList;

  //methods
}

PuntoTrayecto (TrayectoryPoint)

@Entity
@Table(name = "punto_trayecto")
@XmlRootElement
public class PuntoTrayecto implements Serializable {

  //more attributes

  @JoinColumn(name = "id_vehiculo", referencedColumnName = "id")
  @ManyToOne(optional = false, fetch = FetchType.LAZY)
  private Vehiculo idVehiculo;

}

I need to get a "Vehiculo" by the id, so I call the NamedQuery "Vehiculo.findById"

    Query query = em.createNamedQuery("Vehiculo.findById");
    query.setParameter("id", 1);
    Object o = query.getSingleResult();
    Vehiculo vehiculo = (Vehiculo)o;

I get this exception:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'precision, tiempo, velocidad, id_vehiculo FROM punto_trayecto WHERE (id_vehiculo' at line 1

And this is the query that is trying to call

Call: SELECT id, latitud, longitud, precision, tiempo, velocidad, id_vehiculo FROM punto_trayecto WHERE (id_vehiculo = ?)

It corresponds to the other entity "PuntoTrayecto" and I guess this SELECT query is call to fill the List puntoTrayectoList of the "Vehiculo", and the same happens if I use the JPA Controller. What's wrong?

puma91
  • 336
  • 6
  • 15

1 Answers1

3

The problem is probably caused by the column precision. This is a reserved word (according to MySQL). You can check this answer for a workaround

Community
  • 1
  • 1
Tasos P.
  • 3,994
  • 2
  • 21
  • 41