1 Reply Latest reply on Jul 15, 2018 3:54 AM by Arilala Rand

    Error EJB project - java.lang.reflect.UndeclaredThrowableException

    Arilala Rand Newbie

      Hi everyone,

       

      I am getting an exception when I try to call a method from EJB. In my class called ClientEJB I call the method " getAllCategories() " from session EJB implementation

       

      • In my EJB Project:

      This is my entity bean called "Categorie"

       

      @Entity

      @Table(name="CATEGORIE")

      public class Categorie implements Serializable {

      @Id

      @GeneratedValue(strategy=GenerationType.IDENTITY)

      @Column(name="ID_CATEGORIE")

      private Long idCategorie;

      private String libelle;

      private String description;

      @OneToMany(mappedBy="categorie")

      List<Article> listeArticles;

              ....

              /*with getters and setters*/

              ....

      }

      NB: There is an Entity called "Article" who has a bi-directional relation with "Categorie"

      - "Article" has Many-To-One relation with "Categorie"

      - and "Categorie" has One-To-Many relation with "Article"

       

      Below is my "Article" Class :

      @Entity

      @Table(name="ARTICLE")

      public class Article implements Serializable {

      @Id

      @GeneratedValue(strategy=GenerationType.IDENTITY)

      @Column(name="ID_ARTICLE")

      private Long idArticle;

      private String libelle;

      private double prix;

      @Column(name="NOMBRE_STOCK")

      private int nombreStock;

      private String description;

      private byte[] image;

      @ManyToOne

      @JoinColumn(name="ID_CATEGORIE")

      private Categorie categorie;

              ....

              /*with getters and setters*/

              ....

      }

       

      and this is the session bean implementation class: called "CategorieEJBImpl" who implements a two Interfaces (Local and Remote)

       

      @Stateless(name="CATE")

      public class CategorieEJBImpl implements ICategorieLocal,ICategorieRemote {

      @PersistenceContext(unitName="UP_FOURNITURE")

      private EntityManager em;

       

      @Override

      public void addCategorie(Categorie c) {

      em.persist(c);

      }

       

      @Override

      public List<Categorie> getAllCategories() {

      Query req = em.createQuery("select c from Categorie c");

      return req.getResultList();

      }

              ....

      }

       

      • In my java project called "ClientEJB":

      public class ClientEJB {

      public static void main(String[] args) {

      try{

      Properties pr = new Properties();

      pr.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

      Context ctx = new InitialContext(pr);

       

      ICategorieRemote stub = (ICategorieRemote) ctx.lookup("ejb:/FournitureScoEJB/CATE!metier.session.ICategorieRemote");

      List<Categorie> lstC = stub.getAllCategories();

      System.out.println("Liste Categories:");

      for(Categorie c:lstC){

      System.out.println(c.getIdCategorie()+" -- "+c.getLibelle()+" -- "+c.getDescription());

      }

      }

       

      This is the error:

      Exception in thread "main" java.lang.reflect.UndeclaredThrowableException

      at com.sun.proxy.$Proxy0.getAllCategories(Unknown Source)

      at ClientEJB.main(ClientEJB.java:32)

      Caused by: java.lang.ClassNotFoundException: org.hibernate.collection.internal.PersistentBag

      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

      at java.security.AccessController.doPrivileged(Native Method)

      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)

      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

      at java.lang.Class.forName0(Native Method)

      at java.lang.Class.forName(Class.java:274)

      at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:135)

      at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:116)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:892)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1204)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

      at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1677)

      at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1593)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1235)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadCollectionObject(RiverUnmarshaller.java:180)

      at org.jboss.marshalling.river.RiverUnmarshaller.readCollectionData(RiverUnmarshaller.java:771)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:649)

      at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

      at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)

      at org.jboss.ejb.client.remoting.MethodInvocationResponseHandler$MethodInvocationResultProducer.getResult(MethodInvocationResponseHandler.java:107)

      at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:270)

      at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:47)

      at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:272)

      at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:132)

      at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:260)

      at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:399)

      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:140)

      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)

      at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

      ... 2 more

       

      Can someOne please help me how to resolve this issue?

       

      Thanks in Advance.

      Regards,

      Zkarilala

      Exception in thread "main" java.lang.reflect.UndeclaredThrowableException at com.sun.proxy.$Proxy0.getAllCategories(Unknown Source) at ClientEJB.main(ClientEJB.java:32)Caused by: java.lang.ClassNotFoundException: org.hibernate.collection.internal.PersistentBag at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:274) at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:135) at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:116) at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:892) at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1204) at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272) at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209) at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1677) at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1593) at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1235) at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272) at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209) at org.jboss.marshalling.river.RiverUnmarshaller.doReadCollectionObject(RiverUnmarshaller.java:180) at org.jboss.marshalling.river.RiverUnmarshaller.readCollectionData(RiverUnmarshaller.java:771) at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:649) at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209) at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37) at org.jboss.ejb.client.remoting.MethodInvocationResponseHandler$MethodInvocationResultProducer.getResult(MethodInvocationResponseHandler.java:107) at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:270) at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:47) at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:272) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:132) at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:260) at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:399) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:140) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121) at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

      ... 2 more