Friday, December 22, 2006

Netbeans VWP and My JPA1.0 Domain Model in Tomcat 5.5.17

I've been meaning to get this going for a while now and finally got round to it tonight. I have a domain model written using JPA1.0 annotations, Toplink for the implementation and MySQL for the RDBMS. I have it all masked off nicely behind a Session Facade and packaged into a simple jar. i want to call this from my Netbeans Visual Web Pack apps. Here's how I did it:
  1. Create the project making sure that the deployment target is the bundled Tomcat and not AppServer 9 (if you don't then you'll have to set up connection pools etc.)
  2. Add the domain model jar (which includes the persistence.xml file in the META-INF directory) to the new VWP project's libraries
  3. Also add the MySQL JDBC Driver and Toplink Essentials jars to the libraries
  4. Right click on the Application Bean in the Outline View and Add > Property and enter a name for your Session Facade variable and the name of the class
  5. Do this again for the field which you want to store your retreived info from the database (i.e. "username / String")
  6. In the constructor for the Application Bean initialise the Session Facade and then the storage field by calling the newly created facade to get the info you require from the database
  7. On Page1 Design View, drag a Static Text component onto the designer
  8. Switch to the Java view and in the prerender method set the text for the new component to be that which you just looked up and stored
  9. Hit deploy
  10. Et voila!

No comments: