Thursday Jul 19, 2012

NetBeans (team) Responsiveness

When was the last time logging a potential bug/issue for any piece of software, with any vendor, was a pleasure? Most of us rank that with paying taxes, root canals, and visiting in-laws. :-)

Not so with NetBeans. I logged a possible bug report one morning...and by the next morning, it had been assigned, analyzed, and an explanation and workaround posted while code changes and testing take place. In fewer than 24 hours, it effectively went from start to finish from an end-user developer perspective. That may not always be possible, but it speaks very well for the level of commitment of the NetBeans team.

In addition to all the other things I appreciate about NetBeans, such as GlassFish integration/management, superb code generation, polished look-and-feel, ease of navigation, and many other things large and small, add excellent community support/dev engagement to the list. After using other IDEs for years, I could hardly be more pleased.

Those who haven't logged many tool issues may not fully understand this post, but it can be a big deal...and usually at the most inopportune times...  :-)

All the best,

Don't take my word for it, get your own! Visit the NetBeans site to download and check it out for yourself.

(Disclaimer: I work for Oracle, but not on the NetBeans team. I'm just another (very) satisfied user.)

Wednesday Apr 11, 2012

How to Plug a Small Hole in NetBeans JSF (Join Table) Code Generation

I was asked recently to provide an assist with designing and building a small-but-vital application that had at its heart some basic CRUD (Create, Read, Update, & Delete) functionality, built upon an Oracle database, to be accessible from various locations. Working from the stated requirements, I fleshed out the basic application and database designs and, once validated, set out to complete the first iteration for review.

Using SQL Developer, I created the requisite tables, indices, and sequences for our first run. One of the tables was a many-to-many join table with three fields: one a primary key for that table, the other two being primary keys for the other tables, represented as foreign keys in the join table. Here is a simplified example of the trio of tables:

Once the database was in decent shape, I fired up NetBeans to let it have first shot at the code. NetBeans does a great job of generating a mountain of essential code, saving developers what must be millions of hours of effort each year by building a basic foundation with a few clicks and keystrokes. Lest you think it (or any tool) can do everything for you, however, occasionally something tosses a paper clip into the delicate machinery and makes you open things up to fix them. Join tables apparently qualify.  :-)

In the case above, the entity class generated for the join table (New Entity Classes from Database) included an embedded object consisting solely of the two foreign key fields as attributes, in addition to an object referencing each one of the "component" tables. The Create page generated (New JSF Pages from Entity Classes) worked well to a point, but when trying to save, we were greeted with an error: Transaction aborted. Hmm.

A quick debugger session later and I'd identified the issue: when trying to persist the new join-table object, the embedded "foreign-keys-only" object still had null values for its two (required value) attributes...even though the embedded table objects had populated key attributes. Here's the simple fix:

In the join-table controller class, find the public String create() method. It will look something like this:

    public String create() {
        try {
            return prepareCreate();
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;

To restore balance to the force, modify the create() method as follows (changes in red):

    public String create() {

        try {
            // Add the next two lines to resolve:
            return prepareCreate();
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;

I'll be refactoring this code shortly, but for now, it works. Iteration one is complete and being reviewed, and we've met the milestone. Here's to happy endings (and customers)!

All the best,

Wednesday Mar 07, 2012

JPA Code Completion Coming to NetBeans IDE

Over at Geertjan's Blog (click here for article), he details one of the latest additions to the NetBeans daily builds: JPA code completion. I can't help but be excited about the timesaving features this brings to the table!

Being able to see your named queries in NetBeans 7.2 when calling EntityManager.createNamedQuery() is a really slick feature. Being able to CTRL-mouseover the named query (once selected) to see the underlying SQL is equally nice! Sanity checks while coding are ALWAYS welcome.  :-)

Some time back, I dipped my toe into the NetBeans world and found it nice but not overly compelling, choosing to use Eclipse for all Java development of any import. Now, I can't remember the last time I fired up Eclipse.

If you aren't already using NetBeans, visit the NetBeans website to download it and give it a try. It doesn't do everything for all people, but you'd be surprised at all it can do (and will in upcoming versions)...

All the best,

The Java Jungle addresses all things Java (of course!) and any other useful and interesting tools & platforms that help us GET IT DONE. "Artists ship," after all. :)

Your Java Jungle guide is Mark Heckler, a Software Architect/ Engineer and Oracle Developer Evangelist with development experience in numerous environments. Mark's current pursuits and passions all revolve around Java, the Cloud, & the IoT, and leave little time to blog or tweet - but somehow, he finds time to do both anyway.

Mark lives with his very understanding wife in the St. Louis, MO area.

Stay Connected


« February 2017