2016-04-30 5 views
2

の期待されるタイプとパラメータマークアップのためにjava.lang.String型の値を設定するはIllegalArgumentException:あなたは、私は以下の例外を取得、私は以下のクエリを実行するときのjava.math.BigDecimal

public int checkIfQueryExist(String query){ 
    List<Product> products= em.createQuery("SELECT p FROM Product p WHERE p.markup=:markup"). 
      setParameter("markup", query).getResultList(); 
    return products.size(); 
} 

を試みてきました:

Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.lang.String for parameter markup with expected type of class java.math.BigDecimal from query string SELECT p FROM Product p WHERE p.markup=:markup. 
    at org.eclipse.persistence.internal.jpa.QueryImpl.setParameterInternal(QueryImpl.java:937) 
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:593) 
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:1) 
    at enterpriseBeans.Operations.checkIfQueryExist(Operations.java:31) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081) 
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153) 
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786) 
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64) 
    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163) 
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883) 
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822) 
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369) 
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758) 
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746) 
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212) 
    ... 60 more 

どのようにして解決できますか?問題は、スタックトレース

Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.lang.String for parameter markup with expected type of class java.math.BigDecimal from query string SELECT p FROM Product p WHERE p.markup=:markup.

で右が隠されている

+0

BigDecimalを入力しqueryを変換しようと、あなたは、例外の完全なスタックトレースを投稿することができますか? – shays10

+0

私は完全なスタックトレースを追加しました:)本当に助けに感謝します:) – ShayLay22

答えて

2

ちょうどあなたのcheckIfQueryExist方法

+0

これに対処するあなたの提案は何ですか?私はちょうどこれに新しいです。ありがとうございました:) – ShayLay22

+0

'markup'パラメータに間違った型のクエリを実行しています。これは 'String'ですが、実際には' BigDecimal'型です。 – shays10

+0

ここで/どのようにBigDecimalに変更しますか? – ShayLay22

関連する問題