1 Reply Latest reply on Dec 9, 2004 7:55 PM by beonice

    Using UUIDKeyGenerator with Oracle

    beonice Newbie

      Hello.

      I'm developing a simple (read: JSP, JDBC-based, but not using EJBs, JMS, JTA or anything fancy) application. I want to use the UUIDKeyGenerator that is bundled with JBoss, but I am stumped at how to declare and use the UUID Key Generator.

      I've got the uuidkeygenerator.sar in the deploy directory. I've set up the code:
      try {
      InitialContext ic = new InitialContext();
      String idFactoryName = "UUIDKeyGeneratorFactory";

      // get generator factory from JNDI
      try {
      UUIDKeyGeneratorFactory keyGeneratorFactory =
      (UUIDKeyGeneratorFactory)ic.lookup(idFactoryName);

      // get generator instance
      UUIDKeyGenerator idGenerator =
      (UUIDKeyGenerator)keyGeneratorFactory.getKeyGenerator();
      String generatedId = (String)idGenerator.generateKey();
      log("Id is: " + generatedId);
      } catch (Exception ex) {
      log("Threw an exception: " + ex.getMessage());
      }
      } catch (NamingException nex) {
      log("Threw a naming exception: " + nex.getExplanation());
      }

      I double-checked that standardjbosscmp-jdbc has the following declaration:

      <unknown-pk>
      <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
      <unknown-pk-class>java.lang.String</unknown-pk-class>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(32)</sql-type>
      </unknown-pk>

      But when I run the program, here's the exception I get:
      WebModule[/db_test]Threw an exception: UUIDKeyGeneratorFactory not found|#]


      I'm obviously missing something quite fundamental. Can anyone help me out here?

      Thanks,
      Maya

        • 1. Re: Using UUIDKeyGenerator with Oracle
          beonice Newbie

          Duh. Colour me stupid.

          I was thinking about it some more and had an amazing insight.

          I was developing and testing on Sun Java Studio Creator with the Sun One Application Server, and I was happily updating the standardjbosscmp-jdbc.xml file in the JBoss environment.

          Obviously, the Sun One App Server had no clue about the UUIDKeyGenerator at all.

          I exported a war file to JBoss and tested it there ... it works beautifully. :)

          Thanks for checking this post, guys. Sorry to waste your time. :)

          Cheers,
          Maya