The Address entity is at one end of several one-to-many relationships. Notice how
a drop-down menu is generated for each one of the entities at the many end. Since
we wish to assign this address to the customer we just added, we attempt to select
a customer from the Customer combobox.
Clicking on the combobox reveals a cryptic and almost undecipherable (from the
user's point of view) label for our customer. The reason we see this label is because
the labels generated for each item in the combobox come from the toString()
method of the entities used to populate it. We can work around this issue by
modifying the toString() method so that it returns a user-friendly string
suitable to use as a label.
As we can see, the generated code from NetBeans wizards could certainly use
some minor tweaking, such as modifying the toString() methods of each JPA
entity so that it can be used as a label, or modifying the labels on the generated
JSF pages so that they are more user friendly. Nevertheless, as we can see, we can
have a fully-working application that is created with a few clicks of the mouse.
This functionality certainly saves us a lot of time and effort (just don't tell your
boss about it).
In this chapter, we saw the many ways in which NetBeans can help us speed up the
development of applications by taking advantage of JPA.
We saw how NetBeans can generate new JPA classes with all the required annotations
already in place. Additionally, we covered how NetBeans can automatically generate
code to persist a JPA entity to a database table. We also covered how NetBeans can
generate JPA entities from an existing database schema, including the automated
generation of JPQL named queries and validation. Finally, we saw how NetBeans can
generate a complete, visually appealing JSF application from existing JPA entities.