adam bien's blog

JSF 2 + JPA 2 + EJB 3.1 Scaffolding With Netbeans 6.8 in 3 Steps - And The Code Is Even Usable 📎

NetBeans 6.8 comes with a new wizard, which generates a JSF 2 application from an existing database using EJB 3.1 and JPA 2. The resulting code is even usable for real world projects. Also interesting: the generator templates can be easily edited directly from the wizard. This is a serious killer feature and really usable. You can apply the wizard to a Java EE 6 WAR project and deploy it to Glassfish v3. For this purpose:

  1. Create a new WAR application and choose Glassfish v3, Java EE 6 and add JSF 2 as a framework.
  2. Right mouse click on the WAR and choose: "Entity Classes From Database....", choose an existing DataSource, then a Table and don't forget to push the "Create Persistence Unit" button. The result: a JPA entity + persistence.xml.
  3. Right mouse click on the WAR and choose: "JSF Pages from Entity Classes..." and choose the even generated JPA entity. On the second page you can even customize the templates (just click on the link in the right bottom corner). This is really useful.
The resulting code is usable after some tweaks. I used this wizard to generate the code for yesterdays post "(JSF + JPA) - EJB = Bloat". You can also generate JPA controller code without EJB 3 from the context menu choosing "JPA Controller Classes From Entities...". This will, however, result in significantly more plumbing...