QueryException:无法解析属性:com.my.myquiz.entity.Question:的CATID

问题描述 投票:0回答:1

我已经使用Spring数据创建简单的测验,我已经映射问题和类别中的许多使用注释的一个关系。我queering归入指定类别获得随机的问题,但它给上面的错误,我尝试一些替代品。但不工作似乎。

category.Java

@Entity
@Table(name = "categories")
public class Category {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long catId;

    @Column(nullable = false , unique = true)
    private String description;

question.Java

@Entity
@Table(name = "question")
public class Question {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long questionId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "catId", nullable = false, updatable = false)
    @JsonBackReference
    private Category category;

    @Lob
    @Column (nullable = false)
    private String question;

    @Column (nullable = false)
    private String medium;

question repository.Java

@Repository
@Transactional
public interface QuestionRepository extends JpaRepository<Question, Long> {

    @Query("select question from Question question where question.catId = :catId AND question.medium = :medium order by function('RAND')")
    List<Question> getQuestionsForAttempt(@Param("catId") Long catId , @Param("medium") String medium);

    @Query("select question from Question  question where question.catId = : catId")
    List<Question> getQuestionByCategory(@Param("catId") Long catId);
}
spring-boot jpa spring-data-jpa many-to-one
1个回答
0
投票

这是JPQL不是SQL所以你必须去想过在您的查询的相关性:

select question from Question  question where question.category.catId

要么

select question from Question  question  inner join question.category c where c.catId
© www.soinside.com 2019 - 2024. All rights reserved.