The Address entity is at the "one" end of several one-to-many relationships, notice
how a combo box 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 CustomerId combo box.
A better name could be used for the CustomerId field, the reason this is
the label for the combo box is because it matches the property name on
the Address JPA entity, which in turn could have a better name such
as customer . Recall that all entities on this project were automatically
generated from an existing database schema.
Clicking on the combo box reveals a cryptic, almost undecipherable (from the users'
point of view anyway) label for our customer. The reason we see this label is because
the labels generated for each item in the combo box come from the toString()
method of the entities used to populate it. We can work around this issue by modify-
ing 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
tweaking, such as modifying the toString() methods of each JPA entity so that it
can be used as a label, modifying some of the property names on the entities so that
they make more sense to us developers, modifying the labels on the generated JSF
pages so that they are more user-friendly, and last but not least, the pages themselves
are not very visually appealing. It would be a good idea to modify them so that
they don't look so plain. Nevertheless, as we can see we can have a fully working
application completely created by 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
development of applications taking advantage of the Java Persistence API (JPA).
We saw how NetBeans can generate new JPA classes with all 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 JSF application from existing