Install and Use NetBeans 6.9 part 5

 

 

 

What do we have in this session 5?

 

  1. Creating the Session Façade

 

Creating the Session Façade

 

In this exercise you will use a wizard to create a stateless session facade for the Message entity. The EJB 3.1. specification states that business interfaces for session beans are now optional. In this application where the client accessing the bean is a local client, you have the option to use a local interface or a no-interface view to expose the bean. To create the session bean, perform the following steps.

 

Right-click the project node and choose New > Other.

 

NetBeans IDE: selecting the Java web application project, invoking the New - Others Java component menu

 

 

Select Session Beans for Entity Classes from the Java EE category. Click Next.

 

NetBeans IDE: selecting the Java web application project, selecting JavaEE and Session BEans For Entity Classes

 

Select the Message entity (entities.Message) and click Add. Click Next.

 

 

 

 

 

 

 

 

 

 

 

------------------------------------------------------------------------------------------------------------------------------------

NetBeans IDE: selecting the Java web application project, selecting the available entity class

 

NetBeans IDE: selecting the Java web application project, the available entity class was selected

 

Type boundary for the package. Click Finish.

Notice that you did not need to create a business interface for the session bean. Instead, in this application the bean will be exposed to a local managed bean using a no-interface view.

 

NetBeans IDE: selecting the Java web application project, the generated session bean template files

 

When you click Finish, the session facade class MessageFacade.java is created and opens in the Source Editor. The bean class contains the business logic and manages the EntityManager. As you can see in the generated code, the annotation @Stateless is used to declare the class as a stateless session bean component.

In NetBeans IDE 6.9, the wizard generates an AbstractFacade class that contains the business logic and the facade class for the entity extends AbstractFacade as shown below.

 

@Stateless
public class MessageFacade {
    @PersistenceContext(unitName = "SimpleEE6AppPU")
    private EntityManager em;
 

 

NetBeans IDE: selecting the Java web application project, the generated persistence entity source code template

 

When you create the facade for the entity using the wizard, by default the IDE adds the PersistenceContext annotation (@PersistenceContext(unitName = "SimpleEE6AppPU")) to inject the entity manager resource into the session bean component and to specify the name of the persistence unit. In this example the name of the persistence unit is declared explicitly, but the name is optional if the application has only one persistence unit.

The IDE also generates methods in the facade to create, edit, remove and find entities. The EntityManager API defines the methods that are used to interact with the persistence context. You can see that IDE generates some commonly used default query methods that can be used to find entity objects.

 

 

 

 

 

 

 

 

 

 

 

 

-------------------------------------------------------------------

NetBeans IDE: selecting the Java web application project, the generated source code for commonly used default query methods

 

The findAll, findRange and count methods use methods defined in the Criteria API for creating queries. The Criteria API is part of the JPA 2.0 specification that is included in the Java EE 6 specification.

Don’t forget to rectify the warning encountered in MessageFacade.java file as shown below (if any).

 

 

NetBeans IDE: selecting the Java web application project, resolving the warning

 

Press Alt-Enter or click the yellow bulb on the line number to show the hint. Select the given hint.

 

NetBeans IDE: selecting the Java web application project, invoking the hint

 

NetBeans IDE: selecting the Java web application project, the hint resolve the warning

 

 

 

 

 

< NetBeans and Java Web 4 | Java and Friends | NetBeans and Java Web 6 >


NetBeans and Java Web 1 | NetBeans and Java Web 2 | NetBeans and Java Web 3 | NetBeans and Java Web 4 | NetBeans and Java Web 5 | NetBeans and Java Web 6 | NetBeans and Java Web 7 | NetBeans and Java Web 8 | Java and Friends