1 Reply Latest reply on Jan 16, 2006 2:01 PM by Alain Penders

    One problem about EJB 3 persistence!

    Sun Yong Newbie

      Entironment:Jboss4+Eclipse+MS SQLServer2000+EJB3

      servlet:
      ...
      public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
      System.out.println("start.");
      Nationality na = nation.getNa("cn","china");
      System.out.println("cd is " + na.getCode());

      }

      /**
      * Initialization of the servlet.
      *
      * @throws ServletException if an error occure
      */
      public void init() throws ServletException {
      try {
      Context ctx = new InitialContext();
      nation = (Nation)ctx.lookup(Nation.class.getName());
      } catch (NamingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }
      ...

      SessionBean Remote:

      @Remote
      public interface Nation {
      public void addNation(String cd,String name);
      public Nationality getNa(String cd,String name);
      }

      SessionBean:
      public @Stateless class NationBean implements Nation {


      public void addNation(String cd, String name) {

      System.out.println();


      }
      public Nationality getNa(String cd,String name) {
      Nationality nation = new Nationality();
      nation.setCode(cd);
      nation.setName(name);
      return nation;
      }



      }

      EntityBean:

      @Table(name="Nationalities")
      @Entity(access=AccessType.FIELD)
      public class Nationality {
      @Id(generate=GeneratorType.TABLE)
      @Column(name="code")
      private String code;
      @Basic(fetch=FetchType.LAZY)
      @Column(nullable=false)
      private String name;
      public String getCode() {
      return code;
      }
      public void setCode(String code) {
      this.code = code;
      }
      public String getName() {
      return name;
      }
      public void setName(String name) {
      this.name = name;
      }

      }

      Exception:

      Source not found for $Proxy81.getNa(String, String) line: not available

      java.lang.reflect.UndeclaredThrowableException
      at $Proxy81.getNa(Unknown Source)
      at web.TestSevlet.doPost(TestSevlet.java:63)
      at web.TestSevlet.doGet(TestSevlet.java:47)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: java.io.NotSerializableException: test.Nationality
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
      at org.jboss.aop.joinpoint.InvocationResponse.writeExternal(InvocationResponse.java:86)
      at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1304)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1282)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
      at java.rmi.MarshalledObject.(MarshalledObject.java:92)
      at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:214)
      at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
      at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:37)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:88)
      ... 24 more