1 Reply Latest reply on Apr 8, 2002 4:20 PM by Stephen Wittig

    Setting the primary key field in a cmp bean

    Stephen Wittig Newbie

      In an attempt to have unique generated ids I am using a stateless session bean and an entity bean to keep track of the next current id for the different beans. This seems to be working fine and the sequence table is being updated correctly.

      The problem seems to be that when I set the primary key field of the cmp bean it is after the jboss tried to create the record in the table which is resulting in the following error.

      javax.ejb.CreateException: Could not create entity:java.sql.SQLException: General error: Column 'messageid' cannot be null
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invokeHome(Unknown Source)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:258)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
      at $Proxy1.create(Unknown Source)
      at com.mibar.gui.MessageWindow.saveMessage(MessageWindow.java:204)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.mibar.gui.ProgramAction.executeAction(ProgramAction.java:34)
      at com.mibar.gui.ProgramAction.actionPerformed(ProgramAction.java:39)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1458)
      at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1512)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
      at javax.swing.AbstractButton.doClick(AbstractButton.java:285)
      at com.apple.mrj.swing.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:65)
      at java.awt.MenuItem.processActionEvent(MenuItem.java:531)
      at java.awt.MenuItem.processEvent(MenuItem.java:495)
      at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:271)
      at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:261)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:341)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)


      This is the create code in the cmp-bean.
      public Integer ejbCreate() {
      try {
      Context context = new InitialContext();
      Object objRef = context.lookup("SequenceGeneratorBean");
      SequenceGeneratorHome sgh = (SequenceGeneratorHome)PortableRemoteObject.narrow(objRef, SequenceGeneratorHome.class);
      SequenceGenerator generator = sgh.create();
      generator.setName("messagepart");
      messagepartid = new Integer(generator.getNextId());
      System.err.println("Messagepartid="+messagepartid);
      } catch(Exception e) { throw new EJBException(e); }
      return null;
      }

      To JBoss standard error the following is being printed leaving me to believe that the field is getting set correctly.
      [ERROR,Default] Messagepartid=21

      Thanks in advance for any help.