Adam Bien's Weblog

Nice, but hidden, CRUD wizard in Netbeans 6.0

I explored a nice CRUD wizard, which is able to generate a Session Bean from existing JPA entities. I'm not sure, whether this functionality was already existent before Netbeans 6.0.  The wizard is available in the context of an EJB project. You can access the wizard from the menu "New File" (Strg+N), then navigate to the folder "persistence", and choose "Session Beans For Entity Classes". At least a single JPA entity should exist in your project...

The generated code is almost perfect. E.g. I generated a CRUD Session Bean from the following Entity "Bike":

@Table(name = "BIKE")
public class Bike{
    private String name;
    private String description;
    private int expectedkilometers;

//...some code omitted.

 The generated Session Bean looks like: 

public class BikeFacade implements BikeFacadeLocal {
    private EntityManager em;

    public void create(Bike bike) {

    public void edit(Bike bike) {

    public void remove(Bike bike) {

    public Bike find(Object id) {
        return em.find(com.abien.wizardsample.Bike.class, id);

    public List<Bike> findAll() {
        return em.createQuery("select object(o) from Bike as o").getResultList();

The coresponding Local interface is clean and simple as well:

public interface BikeFacadeLocal {

    void create(Bike bike);

    void edit(Bike bike);

    void remove(Bike bike);

    Bike find(Object id);

    List<Bike> findAll();


As mentioned, the code is o.k, but there is still room some for improvement:

  1. Inside the findAll method a simple query and not a NamedQuery was used. This hits not only the performance, but is harder to maintain. The declaration, or reuse of an query at the JPA entity would be much better (but much harder to implement :-)).
  2. The naming of the method "edit" is strange a - "update" or even "merge" would be better.
  3. The @Local annotation could be moved from the interface, to the Session Bean - then the interface would be clean and independent from the EJB 3 API.
  4. Actually a Unit Test could be generated as well :-).
I wondered in a Java EE 5 training, why a student can accomplish his exercise so fast - he used this wizard :-).

NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices


A book about rethinking Java EE Patterns


Been using for some time... this is not hidden ;-)

Posted by Yannick Majoros on October 21, 2009 at 05:54 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments