
org.hibernate.QueryException: could not resolve property: ex_type of: com.planet.develop.Entity.ExpenditureDetail
오류가 발생한 원인
쿼리문을 작성할때의 이름은 데이터베이스가 아닌 JPA로 생성한 필드 이름을 넣어줘야 한다.
/** 카테고리/친(반)환경 태그 별 태그 개수 구하기*/
public Long getCategoryTagCount(User user, LocalDate startDate, LocalDate endDate, money_Type type,EcoEnum eco){
return em.createQuery("select count(*) from Expenditure e " +
"left join ExpenditureDetail ed on e.eno = ed.eno " +
"left join Eco ec on e.eno = ec.expenditure.eno " +
"where e.user = :user and ec.eco = :eco and :startDate<=e.date and e.date <= :endDate and ed.ex_type = :type", Long.class)
.setParameter("user", user)
.setParameter("startDate", startDate)
.setParameter("endDate", endDate)
.setParameter("eco",eco)
.setParameter("type",type)
.getSingleResult();
}
아래 코드를 보면 money_Type의 필드 이름을 exType으로 지었다.
그래서 ed.ex_type = :type가 아닌 ed.exType = :type으로 해야 한다.
public class ExpenditureDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long eno;
@Enumerated(EnumType.STRING)
@Column(name = "ex_way")
private money_Way exWay;
@Enumerated(EnumType.STRING)
@Column(name = "ex_type")
private money_Type exType;
private String memo;
public void update(money_Type type, money_Way way, String memo) {
this.exType = type;
this.exWay = way;
this.memo = memo;
}
}