Java Reference
In-Depth Information
As you can see, these classes will be the factory for the following three kinds of resources:
EntityManager : This will resolve the primary persistence unit since there is
just one persistence unit defined
java.util.Logger : This will trace some information on the server console
FacesContext : This will be used to output some JSF messages on the screen
Producers versus the Java EE 5 @Resource injection
If you have never used the dependency injections framework before, you might wonder
what the benefit of adding an extra layer to produce some container resources is. The reas-
on becomes evident once you need to change some configuration elements, such as the
persistence unit. With the older Java EE 5 approach, you will be forced to change the
@Resource injection's details wherever they are used; however, using a producer meth-
od for it will centralize resource creation, making changes trivial.
Next, we will add some entity producers; let's add the SeatTypeProducer and
SeatProducer classes:
public class SeatTypeProducer {
private SeatTypeDao seatTypeDao;
private List<SeatType> seatTypes;
public void retrieveAllSeatTypes() {
seatTypes = seatTypeDao.findAll();
public List<SeatType> getSeatTypes() {
return seatTypes;
Search WWH ::

Custom Search