My Stack Trace
java.sql.SQLSyntaxErrorException: Unknown column 'i' in 'field list'
5分钟后,我的堆栈跟踪是
Named parameter lastName not bound
这个查询的问题是什么?
<我的接口/strong>
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);
我实体
@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
另外,如果有人知道我在哪里可以找到所有关于不同SQL语言的材料,我将非常感激,因为有时专业人士写
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)
我必须知道所有这些组合!
由于您将查询指定为本机查询,因此您必须使用*
来选择所有。
select * from table i
或
Select i.* from table i