HTML and CSS Reference
In-Depth Information
AppUser is a JPA entity class. @Entity annotation is used for marking the class as an entity class; @Table
annotation is used for explicitly setting the table name that the JPA entity maps to. Both @Named and @RequestScoped
are used to declare the AppUser class as a CDI managed bean in the request scope. If we look into the AppUser class
attributes, we will find the following JPA annotations:
@Id annotation is used to mark the class attribute as a unique identifier.
@Column annotation is used for explicitly setting the column name that the JPA class
attribute maps to.
In the next section, we will see how to configure the JPA persistence unit and create the User Manager EJB.
Application Back End (EJB 3.2 + JPA 2.1)
Now we come to the part about the application back end, which is using EJB 3.2 and JPA 2.1, which are part of the Java
EE 7 platform. In the previous section, we already saw the application's single JPA entity ( AppUser ) class, but we did
not have any information about how to use the entity bean in performing the different database operations. In order
to perform the database operation, we need to define the persistence.xml file which is shown in Listing 10-17.
Listing 10-17. persistence.xml File
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns=" http://xmlns.jcp.org/xml/ns/persistence "
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation=" http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd " >
<persistence-unit name="weatherUnit" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/weatherDB</jta-data-source>
</persistence-unit>
</persistence>
In the persistence.xml file (under /resources/META-INF ), the persistence unit name "weatherUnit" is defined
and transaction type is set to be "JTA" (Java Transaction API). Inside the persistence unit, we define both the JPA
provider class ( org.eclipse.persistence.jpa.PersistenceProvider ) and the <jta-data-source> to be
( jdbc/weatherDB ). The <jta-data-source> element represents the JNDI name of the JDBC data source. Listing 10-18
shows the UserManager Local EJB interface.
Listing 10-18. UserManager Local EJB Interface
package com.jsfprohtml5.weather.model;
import javax.ejb.Local;
@Local
public interface UserManagerLocal {
public AppUser getUser(String userID, String password);
public void registerUser(AppUser user) throws UserExistsException;
}
 
Search WWH ::




Custom Search