Comments on generating a web app from database tables

You think Hibernate is cool? Checkout what NetBeans 5.5 rc1 can do out-of-the-box. It can do O/R mapping, using bundled Hibernate, Top Link, KODO, or a persistence library of your choice. I am going to briefly describe high level steps on generating a web app from an existing Oracle database and generate simple JSF JSPs to view, delete, and update records in your database:

Once you installed Glassfish and NetBeans 5.5 rc1, you should register Glassfish with NetBeans under Runtime tab. Next, you should copy Oracle JDBC driver (class12.jar) to <glassfish_home>/lib directory. In NetBeans, register the same JDBC driver under Driver node, under Databases, within Runtime tab. Create a New Connection by right click on Databases node, within Runtime tab. Choose the driver, enter the correct URL (i.e. jdbc:oracle:thin:@host_name:1521:sid), user name, and password. If you entered correct data and the database is running correctly, you should be able to establish a connection.

Create a new project (File->New Project). Choose Web Application under Web node. On the next screen, enter a name for your web application. On the next screen, choose Java Server Faces. Now, you should have a new project created.

Create a new persistence mapping (File->New File…). Choose Persistence, then Entity Classes from Database. On the next screen, click on the drop-down box next to Data Source and choose New Data Source. Enter “jdbc/oracle” (without the quotes) for JNDI name. Choose the JDBC connection you created earlier. NetBeans will connect to the database and look-up all tables that it can access to generate a table list for you to decide what to map. Choose the tables that you want to map and go to the next screen. You can optionally enter a package name. Click on Create Persistence Unit… By default, NetBeans uses TopLink and that is what I used. Click Create and then click Finish. If TopLink libraries didn’t get added automatically, right click on Libraries node under Projects tab, choose Add Library. Choose TopLink Essentials. You can choose Hibernate if you want. If you do choose Hibernate, make sure the appropriate libraries are added to the project.

Create a generic JSF web GUI for the entity classes (File->NewFile…). Choose Persistence then JSF Pages from Entity Class. Click Add All. On the next screen, click browse and choose Web Pages node. If pages generation works, then you should see sub-directories appear Web Pages node in your project. If page generation failed, you might want to delete the project completely, restart the IDE and give it another try. I had to retry a second time once, so your millage may very.

Expand one of the new sub-directories, right click on a JSP and choose Run File.


19 thoughts on “Comments on generating a web app from database tables

  1. Did you add a new JDBC Driver under Runtime tab in Database –> Drivers? Did you specify the driver jar file and driver class? (i.e.

  2. I am also getting the message “unable to find driver” with MySQL.

    I added the JDBC Driver under Database->Drivers.

    I am able to view the tables on the database in the Runtime section,
    so the connection is working.

  3. Workaround for “unable to find driver” bug:
    While setting up jdbc connector in runtime->databases->drivers->New Driver you should set driver class to: instead of com.mysql.jdbc.Driver Then (in my case) Entity class from database just works 🙂

  4. Thanks for sharing your tip. It’s interesting to know that works for you and not com.mysql.jdbc.Driver. According to this forum post extends com.mysql.jdbc.Driver and act as a wrapper “so old code continues to work”.

  5. I think that if you have a blog, then it is what you need.
    Tell people about something, someone is advertising, to somebody else for something else.
    Personally, I think so.
    Here I have a blog about my travels, but I can not share them with people, because somebody would write that this is spam.
    A hoster will also kick 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s