Core Java

NetBeans Java EE Tip #1 – Entity Classes From Database

The NetBeans IDE is an excellent choice for developing applications of all kind.  Specifically, I use it on a daily basis for developing and maintaining Java EE applications.  Not only has Java EE become much more productive over the past few releases, but the NetBeans IDE has also reduced the time that it takes to develop an application…making Java EE and NetBeans an excellent match!

One of the features that I use the most is the ability to generate entity classes from the database.  NetBeans makes it easy to add an entity class to your project without any coding.

First, right-click on a project package, and choose “New->Entity Classes from Database” (Figure 1).

Figure 1:  New Entity Class from Database
Figure 1: New Entity Class from Database

Next, select a data source, and then choose at least one table from the “Available Tables” list, as shown in Figure 2.

Figure 2:  Choose Table from Available Tables list
Figure 2: Choose Table from Available Tables list

Choose the Project, location, and package to which the entity class will be added.  Then specify any preferences to indicate if you’d like named queries, JAXB annotations, or MappedSuperClass instead of entities. (Figure 3)

Figure 3:  Specify Package name and preferences
Figure 3: Specify Package name and preferences

Lastly, select mapping options for your entity class, as shown in Figure 4.

Figure 4:  Entity Class Mapping Options
Figure 4: Entity Class Mapping Options

Viola…you have an entity class that is ready to use…compliments of NetBeans IDE!

Figure 5:  Completed Entity Class
Figure 5: Completed Entity Class

Josh Juneau

Josh is an application developer and technical writer. He has authored several books for Apress, primarily focusing on Java development. Most recently, he has authored Java EE 7 Recipes, Introducing Java EE 7, and Java 8 Recipes. Josh is a member of the JCP, and he is on the JSF 2.3 Expert Group.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button