Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Linux
- designpattern
- 디자인패턴
- junit
- @NotEmpty
- 점세개
- 백준
- 쉬운 계단 수
- springboot
- 자료구조
- 전치행렬 #C
- 숫자야구
- decorator
- mycp
- 데코레이터패턴
- C
- Spring
- setParameter
- java
- 여러인수
- 자바
- 10951
- @ModelAttribute
- createQuery
- 10844
- pscp
- @Spring
- gradle
- BubbleSorting
- NamedParameterNotBound
Archives
- Today
- Total
...
[JAVA/Spring/Jpa/Criteria] Unable to locate Attribute with the the given name [isOnline] on this ManagedType 오류 해결 본문
이것저것/오류 해결
[JAVA/Spring/Jpa/Criteria] Unable to locate Attribute with the the given name [isOnline] on this ManagedType 오류 해결
gi2 2022. 6. 14. 00:25study 안에 studyInfo를 embeddable로 넣어둬서 당연히 s.get("isOnline")만 해도 불러와질줄 알았는데
s.get("studyInfo").get("isOnline")으로 받아왔어야 했던 거였다...
public List<Study> findStudyListByCondition(String dayOfWeek, String isOnline, String categories){
//Criteria 동적 쿼리 생성
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Study> cq = cb.createQuery(Study.class);
Root<Study> s = cq.from(Study.class);
List<Predicate> criteria = new ArrayList<Predicate>();
if(dayOfWeek != null) criteria.add(cb.equal(s.get("dayOfWeek"),
cb.parameter(String.class, "dayOfWeek")));
if(isOnline != null) criteria.add(cb.equal(s.get("studyInfo").get("isOnline"),
cb.parameter(String.class, "isOnline")));
if(categories != null) criteria.add(cb.equal(s.get("studyInfo").get("categories"),
cb.parameter(String.class, "categories")));
cq.where(cb.and(criteria.toArray(new Predicate[0])));
TypedQuery<Study> query = em.createQuery(cq);
if(dayOfWeek != null) query.setParameter("dayOfWeek",dayOfWeek);
if(isOnline != null) query.setParameter("isOnline",isOnline);
if(categories != null) query.setParameter("categories",categories);
return query.getResultList();
}
}
@Entity
@Getter @Setter
public class Study{
@Id @GeneratedValue
@Column(name = "study_id")
private Long id;
private StudyInfo studyInfo;
@OneToMany(mappedBy = "study", cascade = CascadeType.ALL)
private List<Question> questionList = new ArrayList<>();
@Enumerated(EnumType.STRING)
private RecruitStatus status = RecruitStatus.recruit;
private LocalDateTime postTime = LocalDateTime.now();
public void modifyPersonLimit(int amount){
studyInfo.modifyPersonLimit(amount);
}
/*연관관계 메서드*/
public void setQuestion(Question question){
questionList.add(question);
question.setStudy(this);
}
}
@Embeddable
@Getter
@AllArgsConstructor
public class StudyInfo {
private String title; //스터디제목
private String region; //지역
private String dayOfWeek; //요일
private String isOnline; //대면비대면여부
private String categories; //공부카테고리
private int personLimit; //인원제한
private String content; //소개줄글
protected StudyInfo() {
}
public void modifyAll(String title, String region, String dayOfWeek,
String isOnline, String categories, int personLimit, String content){
this.title = title;
this.region = region;
this.dayOfWeek = dayOfWeek;
this.isOnline = isOnline;
this.categories = categories;
this.personLimit = personLimit;
this.content = content;
}
public void modifyPersonLimit(int amount){
personLimit += amount;
}
}
'이것저것 > 오류 해결' 카테고리의 다른 글
Comments