@Entity
@Table(name = "t_wday")
@IdClass(DayPk.class)
public class Day {
@Id
private Date id;
..
..
}
@Embeddable
public class DayPk {
@Column(name = "idwday")
private Date id;
...
... other key properties
...
}
@Entity
@Table(name = "t_assigned")
@IdClass(AssignedPk.class)
public class Assigned {
@Id
@ManyToOne
private Day day;
...
...
}
@Embeddable
public class AssignedPk {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "t_wday_idwday", referencedColumnName = "idwday"),
@JoinColumn(name = "t_user_iduser", referencedColumnName = "t_user_iduser")
})
private Day day;
...
... other key properties
...
}
当我尝试创建查询时
getSession().createQuery("FROM Day as day WHERE day.user = :user YEAR(day.id) = :year")
它有效但是当我尝试创建查询时
getSession().createQuery("FROM Assigned as assig WHERE YEAR(assig.day.id) = :year")
我有一个例外
could not resolve property: day.id of: com.db.entity.Assigned .....
但是如果我将 DayPk 的归档 id 和实体 Day 中的归档重命名为 idwday 查询是有效的
有人请帮忙