因此,某个时间表属于某个用户,并且可以在多个日期或无时间内处于活动状态。我正在尝试使用通过方法名称创建的查询,其中找到其中userId =“x”并且dateActiveScheduleItem日期为=的时间表“x”。我的日程表回购如下,但我得到的错误是“没有为类型Schedule找到属性dateActiveScheduleItemDate!”
@Repository
public interface ScheduleDao extends JpaRepository<Schedule,Long> {
Schedule findByUserIdAndDateActiveScheduleItemDate(Long
userId,java.util.Date date);
}
Schedule(dateActiveScheduleItems列表是第二个表的链接)
@Entity
public class Schedule {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
@ManyToOne
@JoinColumn(name = "usergroup_id")
private UserGroup userGroup;
private String description;
private boolean master;//is this a schedule for all supervalus(true) or one supervalu(false)
@OneToMany(mappedBy = "schedule",cascade = CascadeType.PERSIST)
private List<DateActiveScheduleItem> dateActiveScheduleItems = new ArrayList<>();
@OneToMany(mappedBy = "schedule",cascade = CascadeType.PERSIST)
private List<MusicScheduleItem> musicScheduleItems = new ArrayList<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public UserGroup getUserGroup() {
return userGroup;
}
public void setUserGroup(UserGroup userGroup) {
this.userGroup = userGroup;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isMaster() {
return master;
}
public void setMaster(boolean master) {
this.master = master;
}
public List<DateActiveScheduleItem> getDateActiveScheduleItems() {
return dateActiveScheduleItems;
}
public void setDateActiveScheduleItems(List<DateActiveScheduleItem> dateActiveScheduleItems) {
this.dateActiveScheduleItems = dateActiveScheduleItems;
}
public List<MusicScheduleItem> getMusicScheduleItems() {
return musicScheduleItems;
}
public void setMusicScheduleItems(List<MusicScheduleItem> musicScheduleItems) {
this.musicScheduleItems = musicScheduleItems;
}
}
DateActiveScheduleItem.java
@Entity
public class DateActiveScheduleItem {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Basic
@Temporal(TemporalType.DATE)
private java.util.Date date;
@ManyToOne
@JoinColumn(name = "schedule_id")
private Schedule schedule;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
答案 0 :(得分:0)
方法名称应为
findByUserIdAndDateActiveScheduleItems_Date
所以它就像这样
@Repository
public interface ScheduleDao extends JpaRepository<Schedule,Long> {
Schedule findByUserIdAndDateActiveScheduleItems_Date(Long
userId,java.util.Date date);
}
因为你的变量名是dateActiveScheduleItems而且里面有你的日期。所以你应该使用_