My Stack Trace
java.sql.SQLSyntaxErrorException: Unknown column 'i' in 'field list'
5 minutes later my Stack Trace was
Named parameter lastName not bound
What is the problem in this query?
My interface
public interface InstructorDao extends JpaRepository <Instructor, Long> {
@Query (nativeQuery=true, value ="select i from Instructor as i where i.firstName like %:firstName% or i.lastName like %:firstName%")
List <Instructor> findInstructorByfirstName (@Param ("firstName") String firstName);
My entity
@Entity
@Table (name = "Instructor")
public class Instructor {
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Column (name = "instructor_id", nullable = false)
private Long instructorId;
@Basic
@Column (name = "name", nullable = false, length = 45)
private String firstName;
@Basic
@Column (name = "lastName", nullable = false, length = 45)
private String lastName;
@Basic
@Column (name = "summary", nullable = false, length = 45)
private String instructorSummary;
@OneToMany (mappedBy = "instructor", fetch = FetchType.LAZY)
private Set <Course> courses = new HashSet<>(); 'i' in 'field lis
Also, if anybody knows where I can find all material about different SQL languages, I will be very grateful, because sometimes professionals write
select i from Instructor as i where i.firstName like %:firstName% or i.lastName like %:firstName% or
select i from Instructor as i where i.user.userEmail =:userEmail or
select * from courses as c where c.course_id in (select e.course_id from enrolled_in as e where e.student_id = :studentId)
I must know all these combinations!
CodePudding user response:
As you specified the query as the native query so you will have to use *
to select all.
select * from table i
OR
Select i.* from table i