Object-relational mapping and the Java Persistence API (JPA)

Practice for Week 9

I've attached a zipped NetBeans project that contains the worked exercises combined into a single project.

To use this project, you will need to first open the Week9 project. Then once the main project is open, you can open each of the sub-projects by right clicking on the modules inside the "Java EE Modules" section of the project.

You should open all of the sub-projects and then right click on Week9 and select "Clean and Build".

I encourage you to attempt the problems yourself before "peeking" at the solutions.

The solutions I've provided are just one of many possible ways to achieve the same effect. If your code is different, but still works, it doesn't necessarily mean that you are "wrong". In fact, your solution may be better than the ones that I have provided. I suggest looking at the differences and understanding why you and I have made different design choices.

I've added an index.xhtml page to the Week9-war project that will take you to each of the solutions.

Note that you should NOT run the Week9-war project directly. You should deploy or run the Week9 project only. Running the Week9 Enterprise Application should bring up index.xhtml from Week9-war for you.

Some notes about the solution:

  1. Once AddressBookController became too big, I split it up into AddressBookController and PersonController to improve the design.
  2. The application could be created using @RequestScoped backing beans. This should be easy if you design your application to work like our previous JSF applications (i.e., a separate view to create people, to create contacts, to edit people, to edit contacts, to delete people, to confirm deleting of people, and to view the contacts of a person). However, I have attempted to combine multiple kinds of actions into a single view. To simplify the code for this, I used @ViewScoped.
  3. Note that @ViewScoped is in the javax.faces.view package (and NOT in javax.faces.bean). The difference is that javax.faces.view is used with @Named while javax.faces.bean is used with @ManagedBean.