Advertise with us

Search Mastertheboss

Our eBooks

Java EE 6 example application


Good. Now the schema is completed, so let's build the Web application. Launch Eclipse.

From the Menu reach File | New | Dynamic Web Project

Choose the name AppStore for your Web application and leave the default Settings.

Now add to your Project the JSF 2.0 facets, by selecting Properties | Projects Facets

jsf 2.0 java ee 6 tutorial

Then, enable JSF 2.0 libraries and then instruct Eclipse where JBoss AS libraries are placed
(under "JBOSS_HOME\server\default\deployers\jsf.deployer")

jsf 2.0 jboss 6

Now let's bind the Datasource definition into our Web application by creating the persistence.xml into the WEB-INF/ folder

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    xmlns="" xmlns:xsi=""
    <persistence-unit name="AppStore" transaction-type="JTA">
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

Ok. Now it's time to build our classes. We will start from the model classes which map the database tables.
Building the Model
Here is the Customer class:

package model;

import javax.persistence.*;
import java.util.List;
import static javax.persistence.FetchType.EAGER;

@Table(name = "customer")
public class Customer implements Serializable {
 private static final long serialVersionUID = 1L;
 @GeneratedValue(strategy = GenerationType.AUTO)
 @Column(name = "ID")
 private int id;
 @Column(name = "COUNTRY")
 private String country;
 @Column(name = "NAME")
 private String name;

 @OneToMany(mappedBy = "customerFK", fetch = EAGER)
 private List<Item> items;

 // Getters and setters here ...


and here is the Item class:

package model;

public class Item implements Serializable {
 private static final long serialVersionUID = 1L;
 private int id;

 private int price;
 private String product;
 private int quantity;
 //bi-directional many-to-one association to Customer
 private Customer customerFK;
 // Getters and setters here ...


© 2021 All Rights Reserved.

Please publish modules in offcanvas position.