1 Reply Latest reply on Sep 6, 2010 12:29 AM by mech123 123

    Getting error java.lang.IllegalArgumentException at creatQuery method

    mech123 123 Newbie
      /*Bean class*/
      public class BookCatalogBean implements Serializable, BookCatalogInterface {
           @PersistenceContext(unitName="EntityBean")
          //   @PersistenceContext   

          EntityManager em;
          protected BookBank book;
        protected Collection <BookBank> pmnList;

          public void addBook(String title, String author, double price) {
          // Initialize the form
          if (book == null)
         book = new BookBank(title, author, price);
          em.persist(book);
          }

        public Collection <BookBank>getAllBooks() {
          System.out.println("BookCatalogInterface.java:getAllBooks");
           pmnList=em.createQuery("from BookBank book ").getResultList();
          System.out.println("BookCatalogInterface.java:getAllBooks...111:"+pmnList);
         return pmnList;
        }
      }

      /*and this is another class BookBank.java */

      package entity.library;

      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.Table;
      import java.util.Collection;
      import javax.persistence.*;
      import java.io.Serializable;

      @Entity
      @Table(name="BookBank")
      public class BookBank implements Serializable {
        long id;
      /*variable declaration*/
        public BookBank() {
          super();
        }

        public BookBank(String title, String author, double price) {
          super();
          this.title = title;
          this.author = author;
          this.price = price;
        }
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)

           // Getter and setter methods for the defined properties..


      }



      and I am getting error :-
      BookCatalogInterface.java:getAllBooks
      javax.ejb.EJBException: EJB Exception: ; nested exception is:
              java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
      Exception Description: Syntax error parsing the query [from entity.library.ConfPmno conf ], line 1, column 0: unexpected token [from].
      Internal Exception: NoViableAltException(32!=[197:1: document : (root= selectStatement | root= updateStatement | root= deleteStatement );]); nested exception is: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
      Exception Description: Syntax error parsing the query [from entity.library.ConfPmno conf ], line 1, column 0: unexpected token [from].
      Internal Exception: NoViableAltException(32!=[197:1: document : (root= selectStatement | root= updateStatement | root= deleteStatement );])
      java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
      Exception Description: Syntax error parsing the query [from BookBank book ], line 1, column 0: unexpected token [from].
      Internal Exception: NoViableAltException(32!=[197:1: document : (root= selectStatement | root= updateStatement | root= deleteStatement );])
              at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1328)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:93)
              at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:91)
              at weblogic.deployment.BasePersistenceContextProxyImpl.invoke(BasePersistenceContextProxyImpl.java:80)
              at weblogic.deployment.TransactionalEntityManagerProxyImpl.invoke(TransactionalEntityManagerProxyImpl.java:26)
              at $Proxy140.createQuery(Unknown Source)
              at entity.library.ConfPmnoBean.getAllBooks(ConfPmnoBean.java:37)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
              at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
              at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
              at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
              at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
              at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
              at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
              at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
              at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proc





      I am not able to resolve the issue,getting error while calling getAllBooks method(createQuery line).
      Please suggest solution