2
My query was built like this, but when it does the request:
@Query(value = "SELECT CT.id FROM CursoTurno AS CT
LEFT JOIN Curso AS C ON C.id = CT.curso_id
INNER JOIN Turno AS T ON T.id = CT.turno_id
WHERE C.id = :curso AND T.id = :turno",
nativeQuery = true)
public CursoTurno findByCursoeTurno(@Param("curso") long curso, @Param("turno") long turno);
Results in that mistake
Caused by: org.postgresql.util.Psqlexception: ERROR: relation "cursoturno" does not exist
Travel Entity
@Entity
@JsonIgnoreProperties({ "cursoTurnos", "unidade" })
@Table(name = "curso")
public class Curso implements Serializable {
@NotNull
@Valid
@OneToMany(cascade = CascadeType.ALL, mappedBy = "curso", orphanRemoval=true)
private List<CursoTurno> cursoTurnos;
Shift Entity
@Entity
@Table(name = "turno")
@JsonIgnoreProperties({ "horarios","cursoTurnos" })
public class Turno implements Serializable {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "turno")
private List<CursoTurno> cursoTurnos;
Entity de Cursoturno
@Entity
@Table(name = "curso_turno")
public class CursoTurno implements Serializable {
@NotNull
@ManyToOne
@JoinColumn(name = "curso_id", referencedColumnName = "id")
private Curso curso;
@NotNull
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "turno_id", referencedColumnName = "id")
private Turno turno;
He’s taking the name of Entity and not the name of the table. I researched how to fix it there and I found nothing convincing.
Are you using Spring Data? (if yes mention the question).
nativeQuery = trueif your intention is to use JPQL. Also note that in JPQL you do not need to specify the Ids manually in joins, e. g.,FROM CursoTurno AS CT LEFT JOIN Curso AS C ON C.id = CT.curso_idflippedFROM CursoTurno ct LEFT JOIN ct.curso c.– Anthony Accioly
Finally: The relationship table
curso_turnohas attributes beyondcurso_idandturno_id? Otherwise I would eliminate the entityCursoTurnoand would use a relationship@ManyToMany.– Anthony Accioly
We resulted in 'SELECT ct FROM Cursoturno ct WHERE ct.curso.id = :idCurso AND ct.turno.id = :idTurno' worked, simple novice knife .... Qqr forma valeuzao ai Anthony by help.
– Marcus Daniel