- JDK 1.5
- GlassFish V2 UR1
- some database (I will use for this tutorial java db but mysql is also a good option)
NetBeans 6.1 Web & Java EE comes already bundled with GlassFish and Tomcat. In just 105 mb!!!. It's awesome to download just one package and a small one.
With NB6.1 you will see how fast it can be to configure/create/code with it.
I will assume that you have already a table in one database of your preference.
After downloading, installing and running NetBeans you will need to create a new project.
Click in File->New Project...choose Enterprise and then Enterprise Application.
Inside the Enterprise Application NetBeans will automatically create for you an EJB Module and Web Application Module.
Type MyApp in the Project Name and leave all of the other settings as it is.
Click in Next and Finish.
Notice that in on the left side in the Projects tab 3 modules were added: MyApp, MyApp-ejb and MyApp-war.
Right click on MyApp-ejb and select New->Other->Persistence->Persistence Unit.
Click in the dropdown box in Data Source and select your DB connection. Then in Table Generation Strategy select create. And leave Use Java Transaction APIs selected.
Once Finish is clicked a persistence.xml tab will open.
The persistence unit will tell your container how the entities will be persisted and managed in the application.
Now right click again in MyApp-ejb and select New->Entity Classes from Database.