Wednesday, November 09, 2005

HyperJaxb, quick start guid

What is HyperJaxb?
HyperJaxb is a set of libraries developed and maintaied by the java.net community. To understand HyperJaxb you should understand both jaxb and Hibernate in some details. HyperJaxb provides a bridge between the jaxb generated objects and the Hibernate mapping. In layman's term, using HyperJaxb, you can simply drop your xsd in a folder, run a magical script and you can see both the java objects as well as relational tables created for you! Aint it promising?

What can we do with Hyperjaxb?
We can do magical things with this new api, if used properly. Especially in a services driven application(SOA), we can completely concentrate on the xsd's to design our application without worrying about the underlying data/object layer or the back end relational layer. We can simply leaverage jaxb, hyperjaxb and hibernate to do the dirty work for us. For instance, I can create a catalog.xsd template to supply catalog xml data to customer webservices and the user facing front end. This xsd will be converted by HyperJaxb into java objects that can be used in application programming as well as relational structure that will store the actuall data! Now say the customer adds a new element in the catalog.xsd; all we need to do is regenerate the jaxb objects and the backend tables! No redesigning of the object and db layer. (Obviously you will have to migrate the data and implement the new business logic if any, manually).

How does HyperJaxb works?
hyperjaxb leverages a cool feature introduced in Hibernate, called as XDoclet. Using XDoclet, you can trick the standard java compiler by adding attribute oriented code snippets right in the program comments. When you compile a xsd using HyperJaxb(instead of the standard jaxb), you end up creating jaxb like java classes with XDoclet annotations in these java files that will contain the mapping information. Now you dont have to write the mapping information on your own. HyperJaxb will generate it all for you.

How to get HyperJaxb working?
  • Download and install the latest stable release of HyperJaxb in c:\program files from here.
  • Create the following folder structure:
    • C:\dev\hyperJaxb
      • hibernate (hibernate property files will sit here)
      • myTestApp (Your sample test application)
        • schema (place your favourite scample catalog.xsd schema file here)
        • sample (sample xml file for the above schema)
  • copy the following files from C:\Program Files\hyperjaxb\tests into c:\dev\hyperjaxb
    • build.xml
    • runtest.bat
    • test.build.xml
  • Modify build.xml
    • Completely delete the following tags:
      • test.all and clean.all
    • Replace them with
      • myTestApp
    • Check the relative location for build.xml
      • It should be ../test.build.xml
    • save and exit this file
  • Modify test.buil.xml
    • Replace main.dir value to
      • C:/Program Files/hyperjaxb
    • Replace hsqldb.lib.dir location to C:/Program Files/jtds-1_1
      • In this step we are replacing the hsql driver by the jtds driver so that we can connect to sqlserver.
  • copy the following files in C:\dev\hyperJaxb\hibernate from C:\Program Files\hyperjaxb\tests\hibernate
    • hibernate.export.properties
    • hibernate.properties
  • Modify both these files:
    • Comment everything.
    • Search for the word server; and below it add the following lines:
      • hibernate.dialect net.sf.hibernate.dialect.SybaseDialect
        hibernate.connection.username sa
        hibernate.connection.password password
        hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
        hibernate.connection.url jdbc:jtds:sqlserver://localhost:1433/hibernateTest
  • Create a blank database in sqlserver with the name hibernteTest, and make sure that sqlserver is up and running on port 1433 on localhost.
  • Go to the command prompt and execute the following command:
    • runtest myTestApp
  • If everything is set properly, you should see database tables created in the database and jaxb files created.
@reference

1 Comments:

Anonymous Anonymous said...

Very quick and simple.
Really useful information.
Thank you.

6:13 AM  

Post a Comment

<< Home