Listing 1

package com.thepeninsulasedge.example.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import static javax.persistence.GenerationType.*;

@Entity
@NamedQueries({
@NamedQuery(name = "Customers.findAll",  query = "select o from Customers o"),
@NamedQuery(name = "Customers.findById", query = "select o from Customers o where o.id = :id")
})
public class Customers implements Serializable {
    private String city;
    private String company;
    private String email;
    @Id
    @GeneratedValue(strategy=SEQUENCE, generator="CUSTOMERS_SEQ")
    @Column(nullable = false)
    private Long id;
    private String name;
    private String phone;
    private String state;
    private String street;
    private String title;
    private String zipcode;

    public Customers() {
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getZipcode() {
        return zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }
}

Listing 2

package com.thepeninsulasedge.example.model;


import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class JavaServiceFacade {
    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("STANDALONE");

    public JavaServiceFacade() {
    }

    private EntityManager getEntityManager() {
        return emf.createEntityManager();
    }

    public Customers mergeCustomers(Customers cust){
        return (Customers)mergeEntity(cust);
    } 

    public Object mergeEntity(Object entity) {
        final EntityManager em = getEntityManager();
        try {
            final EntityTransaction et = em.getTransaction();
            try {
                et.begin();
                em.merge(entity);
                et.commit();
            } finally {
                if (et != null && et.isActive()) {
                    entity = null;
                    et.rollback();
                }
            }
        } finally {
            if (em != null && em.isOpen()) {
                em.close();
            }
        }
        return entity;
    }

    public Customers persistCustomers(Customers c){
        return (Customers)persistEntity(c);
    }

    public Object persistEntity(Object entity) {
        final EntityManager em = getEntityManager();
        try {
            final EntityTransaction et = em.getTransaction();
            try {
                et.begin();
                em.persist(entity);
                et.commit();
            } finally {
                if (et != null && et.isActive()) {
                    entity = null;
                    et.rollback();
                }
            }
        } finally {
            if (em != null && em.isOpen()) {
                em.close();
            }
        }
        return entity;
    }

    /** <code>select o from Customers o</code> */
    public List<Customers> queryCustomersFindAll() {
        return getEntityManager().createNamedQuery("Customers.findAll").getResultList();
    }

    /** <code>select o from Customers o</code> */
    public Customers queryCustomersFindById(int id) {
        return (Customers)getEntityManager().createNamedQuery("Customers.byId").setParameter("id",
		 id).getSingleResult();
    }

    public void removeCustomers(Customers customers) {
        final EntityManager em = getEntityManager();
        try {
            final EntityTransaction et = em.getTransaction();
            try {
                et.begin();
                customers = em.find(Customers.class, customers.getId());
                et.commit();
            } finally {
                if (et != null && et.isActive()) {
                    et.rollback();
                }
            }
        } finally {
            if (em != null && em.isOpen()) {
                em.close();
            }
        }
    }
}