1 2 Previous Next 19 Replies Latest reply on Aug 1, 2007 4:48 AM by jfheintz

    what happen with my entity bean ,need expert help

    ejbiva

      I just a new learner for EJB3.0.I download the jboss-EJB-3.0_Preview_2 for testing ,and the session bean is ok,but when I run the entity bean ,the fatal error occurs .That seems like lots of mess .My environment is Jboss4.2.0GA. The exception just as follow.


      [java] Exception in thread "main" javax.ejb.EJBException:
      java.lang.NullPoi
      nterException
      [java] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxP
      olicy.java:63)
      [java] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)

      [java] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxIntercep
      tor.java:191)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropag
      ationInterceptor.java:76)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(St
      atefulInstanceInterceptor.java:83)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(A
      uthenticationInterceptor.java:77)
      [java] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(
      Ejb3AuthenticationInterceptor.java:106)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagatio
      nInterceptor.java:46)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(As
      ynchronousInterceptor.java:106)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(State
      fulContainer.java:333)
      [java] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
      [java] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invok
      e(AOPRemotingInvocationHandler.java:82)
      [java] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:73
      4)
      [java] at org.jboss.remoting.transport.socket.ServerThread.processInvoc
      ation(ServerThread.java:560)
      [java] at org.jboss.remoting.transport.socket.ServerThread.dorun(Server
      Thread.java:369)
      [java] at org.jboss.remoting.transport.socket.ServerThread.run(ServerTh
      read.java:165)
      [java] at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemot
      eClientInvoker.java:163)
      [java] at org.jboss.remoting.Client.invoke(Client.java:1550)
      [java] at org.jboss.remoting.Client.invoke(Client.java:530)
      [java] at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(Inv
      okeRemoteInterceptor.java:62)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(Cl
      ientTxPropagationInterceptor.java:61)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.security.SecurityClientInterceptor.invoke(S
      ecurityClientInterceptor.java:53)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInte
      rceptor.java:72)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRe
      moteProxy.java:135)
      [java] at $Proxy1.checkout(Unknown Source)
      [java] at org.jboss.tutorial.entity.client.Client.main(Client.java:44)
      [java] at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(Inv
      okeRemoteInterceptor.java:74)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(Cl
      ientTxPropagationInterceptor.java:61)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.security.SecurityClientInterceptor.invoke(S
      ecurityClientInterceptor.java:53)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInte
      rceptor.java:72)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRe
      moteProxy.java:135)
      [java] at $Proxy1.checkout(Unknown Source)
      [java] at org.jboss.tutorial.entity.client.Client.main(Client.java:44)
      [java] Caused by: java.lang.NullPointerException
      [java] at org.jboss.tutorial.entity.bean.ShoppingCartBean.checkout(Shop
      pingCartBean.java:36)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
      sorImpl.java:39)
      [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
      hodAccessorImpl.java:25)
      [java] at java.lang.reflect.Method.invoke(Method.java:585)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:112)
      [java] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(Invo
      cationContextImpl.java:166)
      [java] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke
      (EJB3InterceptorsInterceptor.java:63)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationIn
      terceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.entity.TransactionScopedEntityManagerIntercept
      or.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOpe
      rationsInterceptor.java:47)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)

      [java] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxIntercep
      tor.java:191)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropag
      ationInterceptor.java:76)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(St
      atefulInstanceInterceptor.java:83)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(A
      uthenticationInterceptor.java:77)
      [java] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(
      Ejb3AuthenticationInterceptor.java:106)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagatio
      nInterceptor.java:46)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(As
      ynchronousInterceptor.java:106)
      [java] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInv
      ocation.java:101)
      [java] at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(State
      fulContainer.java:333)
      [java] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
      [java] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invok
      e(AOPRemotingInvocationHandler.java:82)
      [java] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:73
      4)
      [java] at org.jboss.remoting.transport.socket.ServerThread.processInvoc
      ation(ServerThread.java:560)
      [java] at org.jboss.remoting.transport.socket.ServerThread.dorun(Server
      Thread.java:369)
      [java] at org.jboss.remoting.transport.socket.ServerThread.run(ServerTh
      read.java:165)
      [java] Java Result: 1

        • 1. Re: what happen with my entity bean ,need expert help
          wolfc

          Use AS 4.2.1 GA

          • 2. Re: what happen with my entity bean ,need expert help
            ejbiva

            Dear wolfc ,why use AS 4.2.1 GA? any defect with AS 4.2.0?I am sorry one thing I should mentioned,that is I have never create related table in the oracle.because the ejb should create it indtead of me,that is true?

            • 3. Re: what happen with my entity bean ,need expert help
              wolfc

              Don't install any of the preview release into AS 4.2. Use 4.2.1 as installed, by default it has the latest EJB 3 installation.

              • 4. Re: what happen with my entity bean ,need expert help
                ejbiva

                wolfc,I tried it again.but is same. sessionBean is initiated succeesfuly,but the accessing to entity bean failed.why?The Exception is same

                • 5. Re: what happen with my entity bean ,need expert help
                  alrubinger

                  Could you post your code for the Session Bean?

                  S,
                  ALR

                  • 6. Re: what happen with my entity bean ,need expert help
                    ejbiva

                    hi ALRubinger,the SessionBean just as follows
                    @Stateful
                    public class ShoppingCartBean implements ShoppingCart
                    {
                    @Inject
                    private EntityManager manager;
                    private Order order;

                    public void buy(String product, int quantity, double price)
                    {
                    if (order == null) order = new Order();
                    order.addPurchase(product, quantity, price);
                    }

                    public Order getOrder()
                    {
                    return order;
                    }


                    public void checkout()
                    {
                    manager.create(order);
                    }
                    }
                    /// Entity bean
                    @Entity
                    @Table(name = "PURCHASE_ORDER")
                    public class Order implements java.io.Serializable
                    {
                    private int id;
                    private double total;
                    private Collection lineItems;

                    @Id(generate = GeneratorType.AUTO)
                    public int getId()
                    {
                    return id;
                    }

                    public void setId(int id)
                    {
                    this.id = id;
                    }

                    public double getTotal()
                    {
                    return total;
                    }

                    public void setTotal(double total)
                    {
                    this.total = total;
                    }

                    public void addPurchase(String product, int quantity, double price)
                    {
                    if (lineItems == null) lineItems = new ArrayList();
                    LineItem item = new LineItem();
                    item.setOrder(this);
                    item.setProduct(product);
                    item.setQuantity(quantity);
                    item.setSubtotal(quantity * price);
                    lineItems.add(item);
                    total += quantity * price;
                    }

                    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
                    @JoinColumn(name = "order_id")
                    public Collection getLineItems()
                    {
                    return lineItems;
                    }

                    public void setLineItems(Collection lineItems)
                    {
                    this.lineItems = lineItems;
                    }
                    }

                    @Entity
                    @Table(name = "order_line_item")
                    public class LineItem implements java.io.Serializable
                    {
                    private int id;
                    private double subtotal;
                    private int quantity;
                    private String product;
                    private Order order;


                    @Id(generate = GeneratorType.AUTO)
                    public int getId()
                    {
                    return id;
                    }

                    public void setId(int id)
                    {
                    this.id = id;
                    }

                    public double getSubtotal()
                    {
                    return subtotal;
                    }

                    public void setSubtotal(double subtotal)
                    {
                    this.subtotal = subtotal;
                    }

                    public int getQuantity()
                    {
                    return quantity;
                    }

                    public void setQuantity(int quantity)
                    {
                    this.quantity = quantity;
                    }

                    public String getProduct()
                    {
                    return product;
                    }

                    public void setProduct(String product)
                    {
                    this.product = product;
                    }

                    @ManyToOne
                    @JoinColumn(name = "order_id")
                    public Order getOrder()
                    {
                    return order;
                    }

                    public void setOrder(Order order)
                    {
                    this.order = order;
                    }
                    }
                    /////// and testing console as follows
                    public class Client
                    {
                    public static void main(String[] args) throws Exception
                    {
                    InitialContext ctx = new InitialContext();
                    // ShoppingCart cart = (ShoppingCart) ctx.lookup(ShoppingCart.class.getName());
                    //Calculator calculator = (Calculator) ctx.lookup("CalculatorBean/remote");
                    ShoppingCart cart = (ShoppingCart) ctx.lookup("ShoppingCartBean/remote");
                    System.out.println("Buying 2 memory sticks");
                    cart.buy("Memory stick", 2, 500.00);
                    System.out.println("Buying a laptop");
                    cart.buy("Laptop", 1, 2000.00);

                    System.out.println("Print cart:");
                    Order order = cart.getOrder();
                    System.out.println("Total: $" + order.getTotal());
                    for (LineItem item : order.getLineItems())
                    {
                    System.out.println(item.getQuantity() + " " + item.getProduct() + " " + item.getSubtotal());
                    }

                    System.out.println("Checkout");
                    cart.checkout();

                    }
                    }

                    any defect?

                    • 7. Re: what happen with my entity bean ,need expert help
                      waynebaylor

                      instead of


                      @Inject
                      private EntityManager manager;


                      you should try
                      @PersistenceContext(unitName="persistence_unit_name")
                      EntityManager manager;
                      


                      • 8. Re: what happen with my entity bean ,need expert help
                        alrubinger

                        Agree w/ Wayne. Beat me to it. :)

                        • 9. Re: what happen with my entity bean ,need expert help
                          ejbiva

                          ok I will try it ,any way ,Thank you for all ,two gentlemen,:) ,I am from china.nice meet you

                          • 10. Re: what happen with my entity bean ,need expert help
                            jfheintz

                            Hello everybody,

                            I have exactly the same problem. I used to work with Jboss AS 4.2.0.GA. I ahve migrate to Jboss AS 4.2.1.GA with no difference.

                            Have you resolved this?


                            Thanks

                            JF HEINTZ

                            • 11. Re: what happen with my entity bean ,need expert help
                              alrubinger

                              JF HEINTZ -

                              Are you also using @Inject instead of @PersistenceUnit? Post your code?

                              ejbiva, Did this work for you?

                              S,
                              ALR

                              • 12. Re: what happen with my entity bean ,need expert help
                                jfheintz

                                No I have followed your instruction, here is my code:

                                MySite.java:

                                package test;

                                @javax.persistence.Entity
                                @javax.persistence.Table(name="SI_SITE")
                                public class MySite {

                                @javax.persistence.Column(name="siteId")
                                @javax.persistence.Id
                                private java.lang.Long siteId;

                                @javax.persistence.Column(name="name")
                                private java.lang.String name;
                                @javax.persistence.Column(name="description")
                                private java.lang.String description;
                                @javax.persistence.Column(name="staticSite")
                                private boolean staticSite;
                                @javax.persistence.Column(name="status")
                                private int status;

                                public MySite() {
                                }

                                ... getter and setter for the previous attributes

                                }


                                The client (part of a session bean):

                                EjbLocator ejbLocator=EjbLocator.getLocator();
                                MySite siteEJB3=ejbLocator.find(MySite.class, new Long(1));

                                EjbLocator.java:

                                public class EjbLocator {

                                @PersistenceContext(unitName="StatInfoUnit")
                                private EntityManager manager;

                                private static Context ctx;

                                private static EjbLocator instance = new EjbLocator();

                                private EjbLocator() {
                                try {
                                ctx = new InitialContext();
                                } catch (NamingException e) {
                                logger.error(e.getMessage());
                                }
                                }

                                public static EjbLocator getLocator() {
                                return instance;
                                }

                                private T getEjb(Class ejbClass, String name) {
                                try {
                                T service = (T) new InitialContext().lookup("Statinfo/" + name
                                + "/local");
                                return service;
                                } catch (NamingException e) {
                                return null;
                                }
                                }


                                public T find(Class ejb3Class, Object id) {
                                return manager.find(ejb3Class, id);
                                }

                                public void persist(Object ejb3Object) {
                                manager.persist(ejb3Object);
                                }

                                }

                                I have a persistence.xml in META-INF dir:


                                <persistence-unit name="StatInfoUnit">
                                <jta-data-source>java:/StatInfoDS</jta-data-source>
                                <!-- Explicitly define mapping file path, else Hibernate won't find the default -->
                                <mapping-file>META-INF/orm.xml</mapping-file>
                                test.MySite
                                <!-- exclude-unlisted-classes=true: Prevent annotation scanning. In this app we are purely driven by orm.xml -->
                                <exclude-unlisted-classes>false</exclude-unlisted-classes>
                                org.hibernate.ejb.HibernatePersistence




                                </persistence-unit>


                                I have a orm.xml in META-INF dir:
                                <?xml version="1.0" encoding="UTF-8"?>
                                <entity-mappings
                                xmlns="http://java.sun.com/xml/ns/persistence/orm"
                                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
                                version="1.0">
                                <persistence-unit-metadata>
                                </persistence-unit-metadata>
                                </entity-mappings>

                                Deployment is OK but the exception (Nullpointer) occurs when the client part is called, any idea?

                                Thanks a lot for your help,

                                JF

                                • 13. Re: what happen with my entity bean ,need expert help
                                  jfheintz

                                  I reintroduce persistence.xml:


                                  <persistence-unit name="StatInfoUnit">
                                  <jta-data-source>java:/StatInfoDS</jta-data-source>
                                  <mapping-file>META-INF/orm.xml</mapping-file>
                                  <*class>test.MySite</*class>
                                  <exclude-unlisted-classes>false</exclude-unlisted-classes>
                                  <*provider>org.hibernate.ejb.HibernatePersistence</*provider>
                                  <*properties>
                                  <*property name="hibernate.hbm2ddl.auto" value="update" />
                                  <*property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
                                  </*properties>
                                  </persistence-unit>


                                  Note: remove the * (it just for the display in the forum)
                                  Note: If I don't specify the class tag "test.MySite" the log does not show the EJB mapping with the DB

                                  • 14. Re: what happen with my entity bean ,need expert help
                                    alrubinger

                                    Can you please post the stack trace you're getting?

                                    S,
                                    ALR

                                    1 2 Previous Next