1 2 Previous Next 15 Replies Latest reply on Mar 7, 2008 7:22 PM by jgf1

    Doing BMP with EJB3. JNDI problems?

    jgf1

      Hi again.
      Stuck on what I think is an ideosyncrasy in the way JBoss implements JNDI lookups. I was wondering if someone could shed some light?
      Following along with Beginning Java EE 5 book again...
      I have an application with following directory structure:

      BMP
       +beans
       1 StockList.java
       2 StockListBean.java
       +beans_2x
       3 Stock.java
       4 StockBean.java
       5 StockHome.java
       +client
       6 StockClient.java
       +META-INF
       7 Application.xml
       8 Ejb-jar.xml
       9 Jboss.xml
      10 StockList2xBmp.jar (contains 8,9, classes for 3,4,5)
      11 StockListBmpApp.ear (contains 7 & 10)
      12 StockListApp.ejb3 (contains 1 & 2)
      
      11 Gets deployed first, followed by 12.
      6 is run with following command:
      java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=localhost client.StockClient
      
      
      


      Application.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <application xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application5.xsd"
       version="5">
       <display-name>StockListBmpApp</display-name>
       <description>Application description</description>
       <module>
       <ejb>StockList2xBmp.jar</ejb>
       </module>
      </application>
      


      ejb-jar.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
       version="3.0">
       <display-name>StockListBmpJar</display-name>
       <enterprise-beans>
       <entity>
       <ejb-name>StockEjb</ejb-name>
       <home>beans_2x.StockHome</home>
       <remote>beans_2x.Stock</remote>
       <ejb-class>beans_2x.StockBean</ejb-class>
       <persistence-type>Bean</persistence-type>
       <prim-key-class>java.lang.String</prim-key-class>
       <reentrant>false</reentrant>
       <resource-ref>
       <res-ref-name>jdbc/StockDB</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
       </resource-ref>
       <security-identity>
       <use-caller-identity/>
       </security-identity>
       </entity>
       </enterprise-beans>
       <assembly-descriptor>
       <container-transaction>
       <method>
       <ejb-name>StockEjb</ejb-name>
       <method-intf>Remote</method-intf>
       <method-name>setName</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       </method-params>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       <container-transaction>
       <method>
       <ejb-name>StockEjb</ejb-name>
       <method-intf>Remote</method-intf>
       <method-name>getName</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       <container-transaction>
       <method>
       <ejb-name>StockEjb</ejb-name>
       <method-intf>Remote</method-intf>
       <method-name>remove</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       <container-transaction>
       <method>
       <ejb-name>StockEjb</ejb-name>
       <method-intf>Remote</method-intf>
       <method-name>getTickerSymbol</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       </assembly-descriptor>
      </ejb-jar>
      


      Jboss.xml:
      <!DOCTYPE jboss PUBLIC
       "-//JBoss//DTD JBOSS 4.0//EN"
       "http://www.jboss.org/javaee/dtd/jboss_4_0.dtd">
      <jboss>
       <enterprise-beans>
       <entity>
       <ejb-name>StockEjb</ejb-name>
       <jndi-name>beans_2x.Stock</jndi-name>
       <resource-ref>
       <res-ref-name>jdbc/StockDB</res-ref-name>
       <jndi-name>java:/DefaultDS</jndi-name>
       </resource-ref>
       </entity>
       </enterprise-beans>
      </jboss>
      


      StockList.java interface:

      package beans;
      
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import javax.ejb.Remote;
      
      @Remote
      public interface StockList {
       // The public business methods on the StockList bean
       public String getStock(String ticker)
       throws FinderException;
       public void addStock(String ticker, String name)
       throws CreateException;
       public void updateStock(String ticker, String name)
       throws FinderException;
       public void deleteStock(String ticker)
       throws FinderException;
      }
      


      StockListBean:

      package beans;
      
      import beans_2x.Stock;
      import beans_2x.StockHome;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateless;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.PortableRemoteObject;
      
      @Stateless
      public class StockListBean implements StockList {
      
       // The public business methods. These must be coded in the
       // interface also
      
       public String getStock(String ticker)
       throws FinderException {
       try {
       StockHome stockHome = getStockHome();
       Stock stock = stockHome.findByPrimaryKey(ticker);
       return stock.getName();
       } catch (FinderException fe) {
       throw fe;
       } catch (Exception ex) {
       throw new RuntimeException(ex.getMessage());
       }
       }
      
       public void addStock(String ticker, String name)
       throws CreateException {
       try {
       StockHome stockHome = getStockHome();
       Stock stock = stockHome.create(ticker, name);
       } catch (CreateException ce) {
       throw ce;
       } catch (Exception ex) {
       throw new RuntimeException(ex.getMessage());
       }
       }
      
       public void updateStock(String ticker, String name)
       throws FinderException {
       try {
       StockHome stockHome = getStockHome();
       Stock stock = stockHome.findByPrimaryKey(ticker);
       stock.setName(name);
       } catch (FinderException fe) {
       throw fe;
       } catch (Exception ex) {
       throw new RuntimeException(ex.getMessage());
       }
       }
      
       public void deleteStock(String ticker)
       throws FinderException {
       try {
       StockHome stockHome = getStockHome();
       Stock stock = stockHome.findByPrimaryKey(ticker);
       stock.remove();
       } catch (FinderException fe) {
       throw fe;
       } catch (Exception ex) {
       throw new RuntimeException(ex.getMessage());
       }
       }
      
       private StockHome getStockHome()
       throws NamingException {
       // Get the initial context
       InitialContext initial = new InitialContext();
      
       // Get the object reference
       Object objref = initial.lookup("beans_2x.Stock");
       StockHome home = (StockHome)
       PortableRemoteObject.narrow(objref, StockHome.class);
       return home;
       }
      
       // Standard ejb methods
       public void ejbActivate() {}
       public void ejbPassivate() {}
       public void ejbRemove() {}
       public void ejbCreate() {}
       public void setSessionContext(SessionContext context) {}
      }
      


      Stock interface:
      package beans_2x;
      
      import java.rmi.RemoteException;
      import javax.ejb.EJBObject;
      
      public interface Stock extends EJBObject {
       // The public business methods on the Stock bean
       // These include the accessor methods from the bean
      
       // Get the ticker. Do not allow ticker to be set through the
       // interface because it is the primary key.
       public String getTickerSymbol() throws RemoteException;
      
       // Get and set the name
       public String getName() throws RemoteException;
       public void setName(String name) throws RemoteException;
      }
      


      StockBean:

      package beans_2x;
      
      import java.sql.Connection;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.FinderException;
      import javax.ejb.NoSuchEntityException;
      import javax.ejb.ObjectNotFoundException;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.sql.DataSource;
      
      public class StockBean implements EntityBean {
      
       // The persistent fields
       private String tickerSymbol;
       private String name;
      
       // Keeps the reference to the context;
       private EntityContext context;
      
       // Keeps the reference to the db connection
       private Connection connection;
      
       // The access methods for persistent fields
       public String getTickerSymbol() {
       return tickerSymbol;
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       // Standard entity bean methods
      
       public String ejbFindByPrimaryKey(String primaryKey)
       throws FinderException {
      
       boolean result;
      
       try {
       String stmt =
       "select tickerSymbol " +
       "from stock where tickerSymbol= ? ";
       PreparedStatement pstmt =
       connection.prepareStatement(stmt);
       pstmt.setString(1, primaryKey);
       ResultSet rs = pstmt.executeQuery();
       result = rs.next();
       pstmt.close();
       } catch (SQLException ex) {
       throw new EJBException("ejbFindByPrimaryKey: " + ex.getMessage());
       }
      
       if (result) {
       return primaryKey;
       } else {
       throw new ObjectNotFoundException ("Ticker " + primaryKey + " not found.");
       }
       }
      
       public String ejbCreate(String tickerSymbol, String name)
       throws CreateException {
      
       try {
       String findstmt =
       "select tickerSymbol " +
       "from stock where tickerSymbol= ? ";
       PreparedStatement pfindstmt =
       connection.prepareStatement(findstmt);
       pfindstmt.setString(1, tickerSymbol);
       ResultSet rs = pfindstmt.executeQuery();
       boolean findResult = rs.next();
       if (findResult) {
       throw new CreateException("Ticker " + tickerSymbol + "already exists!");
       }
       String stmt =
       "insert into stock values ( ? , ? )";
       PreparedStatement pstmt =
       connection.prepareStatement(stmt);
       pstmt.setString(1, tickerSymbol);
       pstmt.setString(2, name);
      
       pstmt.executeUpdate();
       pstmt.close();
       } catch (SQLException ex) {
       throw new EJBException("ejbCreate: " + ex.getMessage());
       }
      
       this.tickerSymbol = tickerSymbol;
       this.name = name;
      
       return tickerSymbol;
       }
      
       public void ejbPostCreate(String tickerSymbol, String name)
       throws CreateException {}
      
       public void ejbRemove() {
       try {
       String stmt =
       "delete from stock where tickerSymbol = ? ";
       PreparedStatement pstmt =
       connection.prepareStatement(stmt);
      
       pstmt.setString(1, tickerSymbol);
       pstmt.executeUpdate();
       pstmt.close();
      
       } catch (SQLException ex) {
       throw new EJBException("ejbRemove: " + ex.getMessage());
       }
       }
      
       public void ejbLoad() {
       try {
       String stmt =
       "select name from where tickerSymbol = ? ";
       PreparedStatement pstmt =
       connection.prepareStatement(stmt);
       pstmt.setString(1, tickerSymbol);
      
       ResultSet rs = pstmt.executeQuery();
      
       if (rs.next()) {
       this.name = rs.getString(1);
       pstmt.close();
       } else {
       pstmt.close();
       throw new NoSuchEntityException("Ticker: " + tickerSymbol + " not in database.");
       }
       } catch (SQLException ex) {
       throw new EJBException("ejbCreate: " + ex.getMessage());
       }
       }
      
       public void ejbStore() {
       try {
       String stmt =
       "update stock set name = ? " +
       "where tickerSymbol =?";
       PreparedStatement pstmt =
       connection.prepareStatement(stmt);
      
      
       pstmt.setString(1, name);
       pstmt.setString(2, tickerSymbol);
       int rowCount = pstmt.executeUpdate();
       pstmt.close();
      
       if (rowCount == 0) {
       throw new EJBException("Store for " +
       tickerSymbol + " failed.");
       }
       } catch (SQLException ex) {
       throw new EJBException("ejbStore: " + ex.getMessage());
       }
       }
      
       public void ejbPassivate() {}
      
       public void ejbActivate() {}
      
       public void setEntityContext(EntityContext ctx) {
       context = ctx;
      
       try {
       getDatabaseConnection();
       } catch (Exception ex) {
       throw new EJBException("Unable to connect to database. " + ex.getMessage());
       }
       }
      
       public void unsetEntityContext() {
       context = null;
       try {
       connection.close();
       } catch (SQLException ex) {
       throw new EJBException("UnsetEntityContext: " + ex.getMessage());
       }
       }
      
       private void getDatabaseConnection()
       throws NamingException, SQLException {
      
       InitialContext ctx = new InitialContext();
       DataSource ds =
       (DataSource) ctx.lookup("java:comp/env/jdbc/StockDB");
       connection = ds.getConnection();
       }
      }
      


      StockHome:

      package beans_2x;
      
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.EJBHome;
      import javax.ejb.FinderException;
      
      public interface StockHome extends EJBHome {
      
       // The create method for the Stock bean
       public Stock create(String ticker, String name)
       throws CreateException, RemoteException;
      
       // The find by primary key method for the Stock bean
       public Stock findByPrimaryKey(String ticker)
       throws FinderException, RemoteException;
      
      }
      


      StockClient:

      package client;
      
      import beans.StockList;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import javax.naming.InitialContext;
      
      // General imports
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      
      public class StockClient extends JFrame
      implements ActionListener {
       private StockList _stockList;
       private JTextField _ticker = new JTextField();
       private JTextField _name = new JTextField();
       private JButton _get = new JButton("Get");
       private JButton _add = new JButton("Add");
       private JButton _update = new JButton("Update");
       private JButton _delete = new JButton("Delete");
      
       public StockClient() {
       // Get the stock lister
       _stockList = getStockList();
      
       // Add the title
       JLabel title = new JLabel("Stock List");
       title.setHorizontalAlignment(JLabel.CENTER);
       getContentPane().add(title, BorderLayout.NORTH);
      
       // Add the stock label panel
       JPanel stockLabelPanel = new JPanel(new GridLayout(2, 1));
       stockLabelPanel.add(new JLabel("Symbol"));
       stockLabelPanel.add(new JLabel("Name"));
       getContentPane().add(stockLabelPanel, BorderLayout.WEST);
      
       // Add the stock field panel
       JPanel stockFieldPanel = new JPanel(new GridLayout(2, 1));
       stockFieldPanel.add(_ticker);
       stockFieldPanel.add(_name);
       getContentPane().add(stockFieldPanel, BorderLayout.CENTER);
      
       // Add the buttons
       JPanel buttonPanel = new JPanel(new GridLayout(1, 4));
       _get.addActionListener(this);
       buttonPanel.add(_get);
       _add.addActionListener(this);
       buttonPanel.add(_add);
       _update.addActionListener(this);
       buttonPanel.add(_update);
       _delete.addActionListener(this);
       buttonPanel.add(_delete);
       getContentPane().add(buttonPanel, BorderLayout.SOUTH);
       addWindowListener(new WindowAdapter() {
       public void windowClosing(WindowEvent e) {
       System.exit(0);
       }
       });
      
       setSize(330, 130);
       setVisible(true);
       }
      
       private StockList getStockList() {
       StockList stockList = null;
       try {
       // Get a naming context
       InitialContext ctx = new InitialContext();
      
       // Get a StockList object
       stockList
       = (StockList) ctx.lookup("StockListBean/remote");
       // = (StockList) ctx.lookup(StockList.class.getName());
       } catch(Exception e) {
       e.printStackTrace();
       }
       return stockList;
       }
      
       public void actionPerformed(ActionEvent ae) {
       // If get was clicked, get the stock
       if (ae.getSource() == _get) {
       getStock();
       }
      
       // If add was clicked, add the stock
       if (ae.getSource() == _add) {
       addStock();
       }
      
       // If update was clicked, update the stock
       if (ae.getSource() == _update) {
       updateStock();
       }
      
       // If delete was clicked, delete the stock
       if (ae.getSource() == _delete) {
       deleteStock();
       }
       }
      
       private void getStock() {
       // Get the ticker
       String ticker = _ticker.getText();
       if (ticker == null || ticker.trim().length() == 0) {
       JOptionPane.showMessageDialog(this, "Ticker is required");
       return;
       }
      
       // Get the stock
       try {
       String name = _stockList.getStock(ticker.trim());
       _name.setText(name);
       } catch (FinderException fe) {
       JOptionPane.showMessageDialog(this, "Not found!");
       } catch(Exception e) {
       e.printStackTrace();
       }
       }
      
       private void addStock() {
       // Get the ticker
       String ticker = _ticker.getText();
       if (ticker == null || ticker.trim().length() == 0) {
       JOptionPane.showMessageDialog(this, "Ticker is required");
       return;
       }
      
       // Get the name
       String name = _name.getText();
       if (name == null || name.trim().length() == 0) {
       JOptionPane.showMessageDialog(this, "Name is required");
       return;
       }
      
       // Add the stock
       try {
       _stockList.addStock(ticker.trim(), name.trim());
       JOptionPane.showMessageDialog(this, "Stock added!");
       } catch (CreateException ce) {
       JOptionPane.showMessageDialog(this, "Already exists!");
       } catch(Exception e) {
       e.printStackTrace();
       }
       }
      
       private void updateStock() {
       // Get the ticker
       String ticker = _ticker.getText();
       if (ticker == null || ticker.trim().length() == 0) {
       JOptionPane.showMessageDialog(this, "Ticker is required");
       return;
       }
      
       // Get the name
       String name = _name.getText();
       if (name == null || name.trim().length() == 0) {
       JOptionPane.showMessageDialog(this, "Name is required");
       return;
       }
      
       // Update the stock
       try {
       _stockList.updateStock(ticker.trim(), name.trim());
       JOptionPane.showMessageDialog(this, "Stock updated!");
       } catch (FinderException fe) {
       JOptionPane.showMessageDialog(this, "Not found!");
       } catch(Exception e) {
       e.printStackTrace();
       }
       }
      
       private void deleteStock() {
       // Get the ticker
       String ticker = _ticker.getText();
       if (ticker == null || ticker.trim().length() == 0) {
       JOptionPane.showMessageDialog(this, "Ticker is required");
       return;
       }
      
       // Delete the stock
       try {
       _stockList.deleteStock(ticker.trim());
       JOptionPane.showMessageDialog(this, "Stock deleted!");
       } catch (FinderException fe) {
       JOptionPane.showMessageDialog(this, "Not found!");
       } catch(Exception e) {
       e.printStackTrace();
       }
       }
      
       public static void main(String[] args) {
       StockClient stockClient = new StockClient();
       }
      }
      


      Error log:
      javax.ejb.EJBException: java.lang.RuntimeException: beans_2x.Stock not bound
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
      Caused by: java.lang.RuntimeException: beans_2x.Stock not bound
       at beans.StockListBean.addStock(StockListBean.java:41)
       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 org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
       at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:163)
       at org.jboss.remoting.Client.invoke(Client.java:1634)
       at org.jboss.remoting.Client.invoke(Client.java:548)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
       at $Proxy0.addStock(Unknown Source)
       at client.StockClient.addStock(StockClient.java:139)
       at client.StockClient.actionPerformed(StockClient.java:89)
       at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
       at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
       at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
       at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
       at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
       at java.awt.Component.processMouseEvent(Component.java:6041)
       at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
       at java.awt.Component.processEvent(Component.java:5806)
       at java.awt.Container.processEvent(Container.java:2058)
       at java.awt.Component.dispatchEventImpl(Component.java:4413)
       at java.awt.Container.dispatchEventImpl(Container.java:2116)
       at java.awt.Component.dispatchEvent(Component.java:4243)
       at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
       at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
       at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
       at java.awt.Container.dispatchEventImpl(Container.java:2102)
       at java.awt.Window.dispatchEventImpl(Window.java:2440)
       at java.awt.Component.dispatchEvent(Component.java:4243)
       at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
       at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
       at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
       at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:74)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
       at $Proxy0.addStock(Unknown Source)
       at client.StockClient.addStock(StockClient.java:139)
       at client.StockClient.actionPerformed(StockClient.java:89)
       at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
       at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
       at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
       at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
       at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
       at java.awt.Component.processMouseEvent(Component.java:6041)
       at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
       at java.awt.Component.processEvent(Component.java:5806)
       at java.awt.Container.processEvent(Container.java:2058)
       at java.awt.Component.dispatchEventImpl(Component.java:4413)
       at java.awt.Container.dispatchEventImpl(Container.java:2116)
       at java.awt.Component.dispatchEvent(Component.java:4243)
       at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
       at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
       at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
       at java.awt.Container.dispatchEventImpl(Container.java:2102)
       at java.awt.Window.dispatchEventImpl(Window.java:2440)
       at java.awt.Component.dispatchEvent(Component.java:4243)
       at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
       at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
       at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
       at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
      


        • 1. Re: Doing BMP with EJB3. JNDI problems?
          jgf1

          I have already had to modify the source of StockClient to conform
          to the JBoss way in the getStockList method.

          1) I am really surprised JBoss doesn't use the method that is commented out because the current method could lead to class name conflicts if you don't use package prefix...

           private StockList getStockList() {
           StockList stockList = null;
           try {
           // Get a naming context
           InitialContext ctx = new InitialContext();
          
           // Get a StockList object
           stockList
           = (StockList) ctx.lookup("StockListBean/remote");
           // = (StockList) ctx.lookup(StockList.class.getName());
           } catch(Exception e) {
           e.printStackTrace();
           }
           return stockList;
          


          I think the error is in here somewhere:
          private StockHome getStockHome()
           throws NamingException {
           // Get the initial context
           InitialContext initial = new InitialContext();
          
           // Get the object reference
           Object objref = initial.lookup("beans_2x.Stock");
           StockHome home = (StockHome)
           PortableRemoteObject.narrow(objref, StockHome.class);
           return home;
           }
          


          But I am not sure what to do because I am not sure out JBoss is interpretting
          ejb-jar.xml in the node
          <entity>
           <ejb-name>StockEjb</ejb-name>
           <home>beans_2x.StockHome</home>
           <remote>beans_2x.Stock</remote>
           <ejb-class>beans_2x.StockBean</ejb-class>
           <persistence-type>Bean</persistence-type>
           <prim-key-class>java.lang.String</prim-key-class>
           <reentrant>false</reentrant>
           <resource-ref>
           <res-ref-name>jdbc/StockDB</res-ref-name>
           <res-type>javax.sql.DataSource</res-type>
           <res-auth>Container</res-auth>
           <res-sharing-scope>Shareable</res-sharing-scope>
           </resource-ref>
           <security-identity>
           <use-caller-identity/>
           </security-identity>
           </entity>
          


          Following on from the pattern I used on StockClient...
          2) Do I just use Stock/remote?


          • 2. Re: Doing BMP with EJB3. JNDI problems?
            jgf1

             

            "JGF1" wrote:
            But I am not sure what to do because I am not sure out JBoss is interpretting ejb-jar.xml in the <entity> node

            Should read
            "But I am not sure what to do because I am not sure of how JBoss is interpretting ejb-jar.xml in the node."

            • 3. Re: Doing BMP with EJB3. JNDI problems?
              jgf1

               

              "JGF1" wrote:
              Do I just use Stock/remote?

              Alas this didn't work either.
              Just saying Stock not bound now instead!

              • 4. Re: Doing BMP with EJB3. JNDI problems?
                jgf1

                In case anyone wants to build/run this here are commands to run from BMP folder:
                javac -d . beans_2x\*.java
                javac -d . beans\*.java
                javac -d . client\*.java

                jar vcf StockListApp.ejb3 beans/*.class

                jar vcf StockList2Bmp.jar META-INF/ejb-jar.xml META-INF/jboss.xml beans_2x/*.class
                jar vcf StockListBmpApp.ear META-INF/application.xml StockList2xBmp.jar

                Set up database:
                http://localhost:8080/jmx-console/

                Follow Hypersonic URL

                DROP TABLE stock if exists;
                cretae table stock
                (
                tickerSymbol VARCHAR(10),
                name VARCHAR(50),
                CONSTRAINT pk_stock PRIMARY KEY (tickerSymbol)
                );

                From Menu:
                Options>Commit

                • 5. Re: Doing BMP with EJB3. JNDI problems?
                  jgf1

                   

                  "JGF1" wrote:
                  Following on from the pattern I used on StockClient...
                  2) Do I just use Stock/remote?


                  Have also tried
                  Object objref = initial.lookup("beans_2x.Stock/remote");


                  • 6. Re: Doing BMP with EJB3. JNDI problems?
                    jgf1

                    Is there is a way to view the JBoss JNDI registry, so I can ascertain the syntax I need?

                    • 7. Re: Doing BMP with EJB3. JNDI problems?
                      alrubinger
                      • 8. Re: Doing BMP with EJB3. JNDI problems?
                        jgf1

                        Thanks for feedback.
                        Looking at that list the only registered references with "Stock" in them were in the
                        Global JNDI Namespace:

                        StockListBean (class: org.jnp.interfaces.NamingContext)
                         | +- remote (proxy: $Proxy94 implements interface beans.StockList,interface org.jboss.ejb3.JBossProxy)
                        


                        • 9. Re: Doing BMP with EJB3. JNDI problems?
                          jgf1

                          I'm in the dark here.

                          19:14:34,265 INFO [EARDeployer] Init J2EE application: file:/C:/apps/jboss-4.2.2.GA/server/all/deploy/StockListBmpApp.e
                          ar
                          19:14:34,828 INFO [EJB3Deployer] Deployed: file:/C:/apps/jboss-4.2.2.GA/server/all/tmp/deploy/tmp42858StockListBmpApp.e
                          ar-contents/StockList2xBmp.jar
                          19:14:34,843 INFO [EARDeployer] Started J2EE application: file:/C:/apps/jboss-4.2.2.GA/server/all/deploy/StockListBmpAp
                          p.ear
                          19:15:24,968 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
                          19:15:24,968 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=StockListApp.ejb3,name=StockListBean,service=
                          EJB3 with dependencies:
                          19:15:25,093 INFO [EJBContainer] STARTED EJB: beans.StockListBean ejbName: StockListBean
                          19:15:25,125 INFO [EJB3Deployer] Deployed: file:/C:/apps/jboss-4.2.2.GA/server/all/deploy/StockListApp.ejb3
                          
                          
                          Looking at log messages when archives are deployed everything looks fine.
                          So why don't I have other JNDI references.
                          Is there a trailblazer for BMP you can point me to?
                          Cheers. Jeremy
                          


                          • 10. Re: Doing BMP with EJB3. JNDI problems?
                            alrubinger

                            Jeremy:

                            BMP (Bean-Managed Persistence) is an EJB2 construct (noted by the "beans_2x" package in your sample).

                            So for this you'd have to construct a valid EJB2.0 deployable unit complete with ejb-jar.xml and other descriptors. Been a long while since I went this route.

                            What exactly are you trying to accomplish, just work through the book? As a practical measure, using an EJB3/JPA EntityManager with transaction-type="RESOURCE_LOCAL" might be more a line with giving you the finer-grained control of BMT within an EJB3 realm.

                            http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/configuration.html

                            S,
                            ALR

                            • 11. Re: Doing BMP with EJB3. JNDI problems?
                              jgf1

                               

                              "JGF1" wrote:

                              Application.xml:
                              
                              <?xml version="1.0" encoding="UTF-8"?>
                              <application xmlns="http://java.sun.com/xml/ns/javaee"
                               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application5.xsd"
                               version="5">
                               <display-name>StockListBmpApp</display-name>
                               <description>Application description</description>
                               <module>
                               <ejb>StockList2xBmp.jar</ejb>
                               </module>
                              </application>
                              



                              I've been scouring throughmy code again and noticed application5.xsd should be application_5.xsd according to book.
                              I've missed an underscore...
                              But then in the code download they use _1_4.xsd.
                              What version should I use with JBoss 4.2.2.GA?


                              • 12. Re: Doing BMP with EJB3. JNDI problems?
                                alrubinger

                                I'm not familiar with this book, but I'm not sure about it's aims for you. :)

                                Application 1.4 is for JEE1.4 == EJB2, Application 5 is for JEE5==EJB3.

                                S,
                                ALR

                                • 13. Re: Doing BMP with EJB3. JNDI problems?
                                  jgf1

                                   

                                  "ALRubinger" wrote:
                                  I'm not familiar with this book, but I'm not sure about it's aims for you. :)

                                  Application 1.4 is for JEE1.4 == EJB2, Application 5 is for JEE5==EJB3.

                                  S,
                                  ALR

                                  My aim is to become familar enough with Java EE to hopefully get a job at some point. In the book they show BMP and describe there may be instances when you need to resort to this such as a database that doesn't support JDBC, or legacy database.
                                  I hope I don't need to do this too often, as it seems an awful lot of effort..
                                  But they say EJB3 is still backwardly compatible with EJB2 for the BMP part.
                                  For me the book didn't cover in enough detail the reason for all that XML plumbing and the relationship between all the artifacts.
                                  If you know of a good online reference for this type of stuff, so I can get a better insight, I'd appreciate it.
                                  I'm hoping the typo in the DTD for application was the reason JNDI lookup wasn't working.
                                  I'm going to have to dig a little deeper to understand the relationship between EJBObject, EntityBean and EJBHome base classes/interfaces.

                                  I am particularly interested in understanding the correlation between the ejb-jar.xml entity node and the getStockHome method in StockListBean and how it relates to JBoss.
                                  I'll try redeploing everything with the fixed application.xml and see if it makes more sense...

                                  • 14. Re: Doing BMP with EJB3. JNDI problems?
                                    jgf1

                                     

                                    "JGF1" wrote:

                                    I'm hoping the typo in the DTD for application was the reason JNDI lookup wasn't working.

                                    I am afraid things still aren't working.

                                    Still saying beans_2x.Stock not bound arising from call to getStockHome() in StockListBean...
                                    1) Should JNDI entries have appeared when the original EAR is deployed?
                                    2) Should I change the headers for:
                                    jboss.xml javaee -> j2ee
                                    ejb-jar.xml 3.0 -> 2.1
                                    application.xml v5 -> 1.4
                                    Or do you think this is going to be irrelevant?


                                    1 2 Previous Next