Download NetBeans!

20060501 Monday May 01, 2006

The Best Feature Of The Upcoming NetBeans IDE 5.5 (Part 2)

After I blogged about the best feature of the upcoming NetBeans IDE 5.5, a couple of other bloggers sat up and took notice. Rightly so, because the work that has gone into integrating Java EE 5 development into NetBeans IDE for the upcoming 5.5 release is really compelling. Especially when combined with the state-of-the-art Glassfish server, of course. Two bloggers whose responses were particularly enthusiastic (yet enthusiastic in a down to earth, common sense kinda way) were Tim Bray and Philip Jacob Whirlycott.

However, somewhere in that blog entry, Tim wonders out loud: "Geertjan skips lightly over the database-selection wizard; I wonder how much more than "use these tables" it needs?" Well, here's the answer. In step 2 of that blog entry, after you choose the "Entity Classes from Database" menu item, the following dialog box appears:

All that happens here is that you set a database schema or a JNDI data source. And then all the tables available in the referenced database are displayed. At that stage you just select the tables in which you're interested and click Next. Nothing could be simpler and more logical than what has happened so far, right? In the next panel, the world is even more simple and logical:

Here you say what name you want the entity class representing the table to have. And you get default values. Then you're asked where you want the entity classes to appear. Finally, optionally, you set the persistence unit (which you also can do later, if you decide not to do it now):

Each entity class is just a POJO, so they all look like this (in other words, this is the result of going through the wizard, for one of the tables):

package org.me.pkg;

import java.io.Serializable;
import java.math.BigDecimal;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "DISCOUNT_CODE")
@NamedQueries( {@NamedQuery(name = "DiscountCode.findByDiscountCode", query = "SELECT d FROM DiscountCode d WHERE d.discountCode = :discountCode"), @NamedQuery(name = "DiscountCode.findByRate", query = "SELECT d FROM DiscountCode d WHERE d.rate = :rate")})
public class DiscountCode implements Serializable {

    @Id
    @Column(name = "DISCOUNT_CODE", nullable = false)
    private String discountCode;

    @Column(name = "RATE")
    private BigDecimal rate;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "discountCode")
    private java.util.Collection  customer;
    
    /** Creates a new instance of DiscountCode */
    public DiscountCode() {
    }

    public DiscountCode(String discountCode) {
        this.discountCode = discountCode;
    }

    public String getDiscountCode() {
        return this.discountCode;
    }

    public void setDiscountCode(String discountCode) {
        this.discountCode = discountCode;
    }

    public BigDecimal getRate() {
        return this.rate;
    }

    public void setRate(BigDecimal rate) {
        this.rate = rate;
    }

    public java.util.Collection  getCustomer() {
        return this.customer;
    }

    public void setCustomer(java.util.Collection  customer) {
        this.customer = customer;
    }

    public int hashCode() {
        int hash = 0;
        hash += (this.discountCode != null ? this.discountCode.hashCode() : 0);
        return hash;
    }

    public boolean equals(Object object) {
        if (object == null || !this.getClass().equals(object.getClass())) {
            return false;
        }
        DiscountCode other = (DiscountCode)object;
        if (this.discountCode != other.discountCode && (this.discountCode == null || !this.discountCode.equals(other.discountCode))) return false;
        return true;
    }

    public String toString() {
        //TODO change toString() implementation to return a better display name
        return "" + this.discountCode;
    }
    
}

Nice, neat code, right? Annotations instead of deployment descriptors. Java EE 5 is simplified J2EE 1.4. Glassfish is enhanced Sun Java System Application Server. NetBeans IDE 5.5, based purely on the evidence above, combines perfectly with them. Wonderful clean code generated according to the Java EE 5 specification and deployable via Glassfish.

May 01 2006, 08:56:00 AM PDT Permalink

Trackback URL: http://blogs.sun.com/geertjan/entry/the_best_feature_of_the1
Comments:

[Trackback] Drive thru to the IT Blogwatch window, in which Yahoo Tech pops up. Not to mention how to build your own mobile drive-in movie theater...

Posted by Computerworld Blogs on May 02, 2006 at 11:53 AM PDT #

I have tried this demo from and the screens that NetBeans gives me are very different to yours. Which build of 5.5 preview are you using?

Posted by Rory on May 03, 2006 at 06:15 AM PDT #

A very recent one. Daily 5.5 dev build from netbeans.org download page should be fine. What are you seeing that's different to my demo?

Posted by Geertjan on May 03, 2006 at 06:24 AM PDT #

Geertjan, I'm using "Build 2006.02.15", here are the screen shots that I get from following your instructions: http://www.littleprod.co.uk/nb/g1.jpg http://www.littleprod.co.uk/nb/g2.jpg http://www.littleprod.co.uk/nb/g3.jpg As You can see they are slightly different to yours. The only reason I mention it is because yours works, and mine does not. Also you get to choose Toplink as an option. I have used Toplink before in JDeveloper, so I was pleased to see it in NetBeans... if only it would work.

Posted by Rory on May 03, 2006 at 07:00 AM PDT #

Aha... you need to get Glassfish! There's a link at the bottom of netbeans.org that goes to the Glassfish page. That is Sun Java System Application Server 9. Then, when you create the web application, choose that server (after registering it) and select Java EE 5 in the drop-down list... And then it will work!

Posted by Geertjan on May 03, 2006 at 07:07 AM PDT #

ah, right, I have now got Glassfish and the latest NetBeans daily build and its all working perfectly (and its impressive for sure) Thank you, sorry for the trouble.

Posted by Rory on May 03, 2006 at 07:23 AM PDT #

Trouble? Whaddahellareyatalkingaboutdude??? Great to know you got it working and can see its impressivosity!!!

Posted by Geertjan on May 03, 2006 at 05:00 PM PDT #

very nice!

Posted by 192.127.94.7 on May 03, 2006 at 08:06 PM PDT #

ggg

Posted by 81.208.105.163 on May 05, 2006 at 04:28 AM PDT #

fsdsfsf

Posted by 12.171.224.124 on May 05, 2006 at 12:36 PM PDT #

blah, blah, blah. none of that code is needed if you use Ruby of Rails.

Posted by david on May 05, 2006 at 01:53 PM PDT #

Ruby/Rails would be great if it could be used as an Apache module, plus, a nice GUI IDE in the arena of Java studio Creator would make it a cracking setup that would knock PHP out cold and give J2EE a run for its money. That said, nice to see J2EE getting easier...

Posted by matt Verran on May 06, 2006 at 03:37 AM PDT #

Hi, can I start the CRUD code generation from the POJOs themselves instead of from the database tables? Looking forward to see this new Netbeans, I think a JPA based code generator like this is really impressive :)

Posted by Alessio Pace on May 07, 2006 at 01:46 AM PDT #

hello

Posted by 213.205.199.234 on May 07, 2006 at 11:46 AM PDT #

I tried the example and I was unable to see any table data. When I click on a link from the index.jsp page such as list of ProductCode, I get this error : javax.servlet.ServletException: Unable to retrieve EntityManagerFactory for unitName XYZPU. I use the latest NetBeans 5.5 daily build and Sun Java System Application Server.

Posted by Martin on May 07, 2006 at 04:16 PM PDT #

Hi Alessio -- that is exactly what happens: the JSF files are generated from the POJOs. Hi Martin -- please check that the "Source Level" (right-click the project node, choose Properties, and on the first page you'll see "Source Level" setting) is set to 1.5. Other people who left comments above -- thanks!

Posted by Geertjan on May 07, 2006 at 06:27 PM PDT #

I saw the screen capture shows using toplink. Any support for Hibernate?

Posted by Jap on May 08, 2006 at 12:10 AM PDT #

I am getting one additional error along with the same error that Martin is getting. I downloaded the latest version of Glassfish and Netbeans5.5 daily build (netbeans-5_5-daily-bin-200605050500-windows-5_May_2006_0500.exe) Initally I got a deployment error with an error message that the persistence xml should not have version as part of the xml. Once I removed that, the deployment worked fine but I got the same error as Martin reported above. I am using source 1.5 (JDK 1.5_04) to be exact. I hope they fix the bugs but hey this is beta, so it is expected. Any idea when it will go live?

Posted by Seth on May 08, 2006 at 12:52 AM PDT #

yeah... hibernate support would be great. I tried to get it to work, but am still having trouble. I want to use it with tomcat and not glassfish. I added the hibernate jars (including the hibernate entity manager and annotations) and added it as a persistence unit, and generated the entity classes from database. That worked fine. But then I went ahead and created the facade for the entity classes, and it seems to be broken (it generates "changeMyName" methods). I fixed it by hand, but i am still getting an error at the annotation: @javax.ejb.Stateless it says package does not exist. Does anyone know how can i fix this? where do i get this package from, without the use of glassfish. (i want to be able to use it with tomcat).

Posted by anonc on May 08, 2006 at 06:53 AM PDT #

follow up on my previous message.... I think i got it to work. i was missing some jars that I had to include.... (specifically the ones in the lib directory of the hibernate core, entity manager and annotations. So this message goes to Jap. It should work with hibernate.

Posted by anonc on May 08, 2006 at 08:45 AM PDT #

Hi anonc, you're doing some great experimenting. The functionality in question was initially made for Glassfish, so if you're managing to get it to work for Tomcat and Hibernate, then that's fantastic. Maybe you could provide steps for how to get this to work? I'd like to try it myself!

Hi Seth, I don't know when this is planned to go live, but great to see so many are trying it out. Are you sure you have 1.5 source level selected as well as Java EE 5? (The latter during creation, the former afterwards in the Project Properties dialog box).

Posted by Geertjan on May 08, 2006 at 08:50 AM PDT #

I verified that source level is set to 1.5 and it was ok. I noticed that in sun-web.xml, DOCTYPE directive is referencing an invalid url : http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd Do I have someting else to install in addition to NetBeans 5.5 daily build and Sun Java System Application Server?

Posted by Martin on May 08, 2006 at 08:54 AM PDT #

I have a probleme with this cause I use Netbeans5.5,JDK 1.5 and Tomcat 5.5 when I create a new entity class from database I see a red message showing : "To create entity classes in this project,the Java source level must be at least 1.5". I don't know what I do.

Posted by Maodo DIOP on November 22, 2006 at 06:58 AM PST #

Right-click the project, choose Properties, and change the source level in the Sources tab.

Posted by Geertjan on November 22, 2006 at 07:12 AM PST #

I am using NetBeans5.5, When I tried to run one of the sample ejb projects, I got the compilation error saying package java.ejb.Statless does not exist. How to fix this, please suggest...

Posted by Sarvesh Bhatnagar on July 06, 2007 at 03:12 AM PDT #

Please write to nbusers@netbeans.org. Thanks.

Posted by Geertjan on July 06, 2007 at 03:16 AM PDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed