JPA实体中的加入请求

时间:2018-10-03 09:26:59

标签: java sql spring hibernate jpa

我正在使用带有休眠jpa和spring的API,并且我想与jpa实体管理器进行联接,而我仍然遇到此错误:

org.hibernate.QueryException: could not resolve property: game_id of: jack.persistence.models.Progress [from jack.persistence.models.Game g, jack.persistence.models.Progress p where g.id = p.game_id and p.user_id = 2]

这是请求:

public List findAllAndProgress() {
    return entityManager.createQuery("from Game g, Progress p where g.id = p.game_id and p.user_id = 2")
            .getResultList();
}

游戏实体的字段:

@Id
@Column(name="id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;

@Column(name = "title")
private String title;

@Column(name = "genre")
private String genre;

@Column(name = "year")
private String year;

进度实体字段:

@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "game_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JsonIgnore
private Game game;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "user_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JsonIgnore
private User user;

@OneToMany(targetEntity = Task.class, cascade = CascadeType.ALL)
private List taskList;

private double completion;

最后,在数据库中,以下是冬眠创建的游戏和进度表的字段:

Game (id, genre, title, year)
Progress (id, completion, game_id, user_id)

0 个答案:

没有答案