私は様々なユーザに表示するための通知のテーブルを必要とするWebアプリケーションを作成しています。なんらかの理由で私が書いたJPQLクエリはjava.lang.IllegalArgumentExceptionを投げています。私のアプリケーションは、完全に動作する同一のアプローチ(afaik)を使用して構造化され照会されたトランザクションテーブルをすでに持っています。JPQLとエンティティ(java.lang.IllegalArgumentException)
変数名と文字の大文字と小文字を数時間変化させてコードをシャッフルしていますが、毎回例外が発生しています。誰かが私が間違っていることを知っていますか?
次のように私のNotificationEntityがある:
@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
}
JPQLクエリは、以下の方法とのインタフェース(NotificationStorageService)を実装するEJB(NotificationStorageServiceBean)から呼び出されます。
@Override
public synchronized List<NotificationEntity> getUserNotificationList(String username)
{
List notifications;
notifications = em.createNamedQuery("fetch_user_notifications").setParameter("notificationrecipient", username).getResultList();
return notifications;
}
とEJBメソッドは、これらのメソッドの引数を提供するために現在ログインしているFacesContextのユーザーを使用して、自分の.xhtml UI用のCDIバッキングBeanから呼び出されます。
@EJB
NotificationStorageService notificationStore;
public List<NotificationEntity> getUserNotificationList()
{
return notificationStore.getUserNotificationList(this.currentUser);
}
私が手に正確なエラーは次のとおりです。 java.lang.IllegalArgumentExceptionが:あなたはNotificationEntity N Nからクエリ文字列SELECT Nには存在しませんnotificationrecipientの名前を使用してパラメータ値を設定することを試みてきました。 notificationrecipient =:ユーザー名。
ありがとうございました!これは私を夢中にさせている。私は明らかにsetParameterメソッドを誤解していました。名前付きクエリで設定したパラメータではなく、エンティティフィールドを参照することを意図していると思いました。エンティティフィールド、テーブルの列ヘッダー、およびパラメータがすべて同じ名前を共有しているため、これはトランザクションテーブルで機能しました – TNARGI