英文:
issue in running the mysql query
问题
@Query(value="select sqla.questionBO from StudBO sqla where sqa.questionBO.id != null and sqa.lessionId = :lessionId and sqa.studentBO.id=:studentId ORDER BY sqa.attemptedOn DESC limit 1", nativeQuery=true)
List<QuestionBO> getSQues(@Param("studentId") Long studentId, @Param("lessionId") Long lessionId);
// ...
@Table(name = "student_question_attempt")
public class StudQuesAttemptBO implements Serializable {
@Column(name = "ATTEMPTED_ON")
private Timestamp attemptedOn;
//@Column(name = "STUDENT_ID")
@ManyToOne
@JoinColumn(name = "STUDENT_ID")
private StudentBO studentBO;
// @Column(name = "QUESTION_ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "QUESTION_ID")
private QuestionBO questionBO;
@Column(name = "SCORE")
private Double score;
@Column(name = "LESSION_ID")
private Long lessionId;
}
// ...
if i use table name instead of BO then getting:-
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Unknown column 'sqla.questionBO' in 'field list'
英文:
Query: -
@Query(value="select sqla.questionBO from StudBO sqla where sqa.questionBO.id != null and sqa.lessionId = :lessionId and sqa.studentBO.id=:studentId ORDER BY sqa.attemptedOn DESC limit 1", nativeQuery=true)
List<QuestionBO> getSQues(@Param("studentId") Long studentId,
@Param("lessionId") Long lessionId);
I'm upgrading my MySQL from v5 to v8 earlier I was not using nativeQuery = true variable and it was working fine, but I think now I have to use native Query as I'm using the limit function.
If I don't use nativeQuery then I get "antlr.NoViableAltException: unexpected token: limit
"
error at tomcat startup.
But when I use nativeQuery I get the table not found error "ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Table 'latest.studquesattemptbo' doesn't exist
" when this method is called.
I checked my.ini file and there "lower_case_table_names=1" is already present as pointed in this link "https://knowledge.broadcom.com/external/article/47334/enterprise-dashboard-error-sqlexceptionh.html"
Edit1:-
its BO.
@Table(name = "student_question_attempt")
public class StudQuesAttemptBO implements Serializable {
@Column(name = "ATTEMPTED_ON")
private Timestamp attemptedOn;
//@Column(name = "STUDENT_ID")
@ManyToOne
@JoinColumn(name = "STUDENT_ID")
private StudentBO studentBO;
// @Column(name = "QUESTION_ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "QUESTION_ID")
private QuestionBO questionBO;
@Column(name = "SCORE")
private Double score;
@Column(name = "LESSION_ID")
private Long lessionId;
Edit2:-
if i use table name instead of BO then getting:-
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Unknown column 'sqla.questionBO' in 'field list'
答案1
得分: 1
使用“Pageable firstRecord = PageRequest.of(0, 1);
”而不是更改查询为本机查询,并将其传递给方法调用的参数。
英文:
instead of changing the query to native query use "Pageable firstRecord = PageRequest.of(0, 1);
" and pass this in the parameter of the method call
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论