1 Reply Latest reply on Nov 1, 2004 3:46 AM by luc.texier

    Problem on compiling Duke bank's example on a remote machine

      Hi,


      I've another question about Duke Bank's example discussed in "Getting Started with JBoss"

      If I were to use Hypersonic database server but I'm compiling on a separate machine, a machine different from the server running JBoss + Hypersonic, what I need to change?

      It rejects my connection attempt when I try "ant -f jboss-build.xml db-create-table"

      thanks,
      jackling

        • 1. Re: how to create ejbSelect using Xdoclet
          luc.texier

          Thanks, timkk.

          Indeed it works fine when you just put in the <query-method> stuff into jbosscmp-jdbc.xml by hand. For some reason XDoclet does not generate this for you with ejbSelect methods, while it does so for ejbFind. (Could this be a bug in XDoclet? or am I using the wrong tags?)

          If you're using Eclipse as your IDE you could use the Lomboz and/or JBoss IDE plugins. They both user XDoclet under the hood. It shields you somewhat from the daunting XDoclet and ANT configs you would need otherwise and they both integrate nicely with Eclipse. For an J2EE starter like me Lomboz/Eclipse makes for a good pair.

          On the Double / Integer issue I must correct myself; you are right! JBoss *does* seem to map a Double java type on the SQL INT type configured in the deployment descriptor and EJB class. Really anoying.

          I did not notice this until now since I had not proceeded yet to the point that I actually received a valid object back from the ejbSelect without JBoss throwing exceptions at me about my EJB-QL. And in the Lomboz/XDoclet generated interfaces and deployment descriptors all seemed fine. The last exception I had to fix was a ClasscastException at the point where the ejbSelect was called ; - ) The returned type indeed was Double instead of Integer.

          I solves this by casting the Double returned by the ejbSelect into an Integer in my wrapper home method, which I need anyway, since the ejbSelect is only visible to EJB's and normally you'd like it exposed to the outside world:

          /**
           * @ejb.select
           * query="SELECT MAX(m.myPrimKey) FROM MyTable AS m"
           * @jboss.query
           * query="SELECT MAX(m.myPrimKey) FROM MyTable AS m"
           */
          abstract public Double ejbSelectMyPrimKey() throws FinderException;
          
          /**
           * @ejb.home-method
           * view-type="local"
           */
          public static Integer ejbHomeGetNextPrimKey() throws Exception {
           int nextKey = 1 + ejbSelectMyPrimKey().intValue();
           return new Integer(nextKey);
          }


          Now the method getNextPrimKey() can be called on the (local) home object of the EJB to find the next primary key to be used in the create() method. Ofcourse you need to wrap getNextPrimKey() and create() in a user transaction to ensure concurrent inserts into your database succeed.

          I guess all this pretty much answer your question too, Ben!

          Cheers,
          Frank