Geertjan's Blog

  • May 1, 2006

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

Geertjan Wielenga
Product Manager
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;
@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 {
@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.

Join the discussion

Comments ( 26 )
  • Computerworld Blogs Tuesday, May 2, 2006
    [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...
  • Rory Wednesday, May 3, 2006
    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?
  • Geertjan Wednesday, May 3, 2006
    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?
  • Rory Wednesday, May 3, 2006
    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.
  • Geertjan Wednesday, May 3, 2006
    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!
  • Rory Wednesday, May 3, 2006
    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.
  • Geertjan Wednesday, May 3, 2006
    Trouble? Whaddahellareyatalkingaboutdude??? Great to know you got it working and can see its impressivosity!!!
  • guest Wednesday, May 3, 2006
    very nice!
  • guest Friday, May 5, 2006
  • guest Friday, May 5, 2006
  • david Friday, May 5, 2006
    blah, blah, blah. none of that code is needed if you use Ruby of Rails.
  • matt Verran Saturday, May 6, 2006
    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...
  • Alessio Pace Sunday, May 7, 2006
    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 :)
  • guest Sunday, May 7, 2006
  • Martin Sunday, May 7, 2006
    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.
  • Geertjan Sunday, May 7, 2006
    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!
  • Jap Monday, May 8, 2006
    I saw the screen capture shows using toplink. Any support for Hibernate?
  • Seth Monday, May 8, 2006
    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
    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?
  • anonc Monday, May 8, 2006
    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:
    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).
  • anonc Monday, May 8, 2006
    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.
  • Geertjan Monday, May 8, 2006
    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).

  • Martin Monday, May 8, 2006
    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?
  • Maodo DIOP Wednesday, November 22, 2006
    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.
  • Geertjan Wednesday, November 22, 2006
    Right-click the project, choose Properties, and change the source level in the Sources tab.
  • Sarvesh Bhatnagar Friday, July 6, 2007
    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...
  • Geertjan Friday, July 6, 2007
    Please write to nbusers@netbeans.org. Thanks.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.