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.