다양한 사용자에게 표시 할 알림 테이블이 필요한 웹 응용 프로그램을 만들고 있습니다. 어떤 이유로 나는 작성한 JPQL 쿼리가 java.lang.IllegalArgumentException을 던지고있다. 내 응용 프로그램에는 이미 동일한 접근 방식 (afaik)을 사용하여 구조화되고 쿼리 된 트랜잭션 테이블이 있으며 완벽하게 작동합니다.JPQL과 엔티티 (java.lang.IllegalArgumentException)
나는이 코드가 작동하도록하기 위해 변수 이름과 문자 케이스를 변경하면서 코드를 뒤섞고 있지만 매번 예외가 발생합니다. 아무도 내가 잘못 가고있는 생각이 있습니까? 다음과 같이
내 NotificationEntity은 다음과 같습니다
JPQL 쿼리는 다음과 같은 방법으로 인터페이스 (NotificationStorageService) 구현하는 EJB (NotificationStorageServiceBean)에서 호출@Table(name="notificationentity")
@NamedQuery(name="fetch_user_notifications", query="SELECT n FROM NotificationEntity n WHERE n.notificationrecipient=:username")
@Entity
public class NotificationEntity implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
String notificationSender;
@NotNull
String notificationrecipient;
... other fields + methods
}
:
@Override
public synchronized List<NotificationEntity> getUserNotificationList(String username)
{
List notifications;
notifications = em.createNamedQuery("fetch_user_notifications").setParameter("notificationrecipient", username).getResultList();
return notifications;
}
그리고 EJB를 메서드는 현재 .xhtml UI 용 CDI 백킹 빈에서 호출되며, 현재 로그인 한 FacesContext의 사용자를 사용하여 이러한 메서드에 대한 인수를 제공합니다.
@EJB
NotificationStorageService notificationStore;
public List<NotificationEntity> getUserNotificationList()
{
return notificationStore.getUserNotificationList(this.currentUser);
}
내가 얻을 정확한 오류는 다음과 같습니다 java.lang.IllegalArgumentException가 : 당신은 여기서 n NotificationEntity n은 N을 선택 쿼리 문자열에 존재하지 않는 notificationrecipient의 이름을 사용하여 매개 변수 값을 설정하려고했습니다. notificationrecipient = : 사용자 이름.
정말 고마워요! 이것은 나를 미치게했다. 나는 분명히 setParameter 메소드를 오해하고있다. 필자는 이름이 지정된 쿼리에서 설정 한 매개 변수가 아니라 엔터티 필드를 참조 할 예정이라고 생각했습니다. 엔터티 필드, 테이블 열 머리글 및 매개 변수가 모두 같은 이름을 공유했기 때문에이 테이블이 내 트랜잭션 테이블에서 작동했습니다. – TNARGI