Java Swing / JPA / Oracle inserting twice
<p>Probably a newbie Java...thing but here it is. Using JPA to call a INSERT stored procedure to an Oracle 11g database. Everything works fine in terms of getting the data to the DB table. </p>

<p>I've wrapped the JPA code into a Java Swing application. My problem is the data gets submitted twice somehow or another. I have a <code>JOptionPane.showMessageDialog</code> that displays when I submit the data. That only shows once. But when I query the table, there are two entries in the table. Here's my code....</p>

<p><strong>Button code</strong></p>

<pre><code>JButton btnSubmit = new JButton("Submit");
btnSubmit.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
        AddNewCustomer();
    }
});
btnSubmit.setBounds(24, 341, 91, 23);
frmNewCustomer.getContentPane().add(btnSubmit);
</code></pre>

<p><strong>Action methods</strong></p>

<pre><code>public void AddNewCustomer() {
    Customer.AddCustomer(this.txtFirstName.getText(),
            this.txtLastName.getText(), this.txtAddress.getText(),
            this.txtCity.getText(), this.txtState.getText(),
            this.txtEmail.getText(), this.txtPhone.getText());

    JOptionPane.showMessageDialog(frmNewCustomer, "Added new customer",
            "Status", 1);
}

protected static void AddCustomer(String sFirstName, String sLastName,
        String sAddress, String sCity, String sState, String sEmail,
        String sPhone) {
    try {
        factory = Persistence
                .createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        EntityManager em = factory.createEntityManager();
        em.getTransaction().begin();

        Query q = em.createNamedQuery("AddCustomer");
        q.setParameter("p_PHONE", sPhone);
        q.setParameter("p_STATE", sState);
        q.setParameter("p_FIRST_NAME", sFirstName);
        q.setParameter("p_ADDRESS", sAddress);
        q.setParameter("p_EMAIL", sEmail);
        q.setParameter("p_CITY", sCity);
        q.setParameter("p_LAST_NAME", sLastName);
        int r = q.executeUpdate();
        em.getTransaction().commit();

        List results = q.getResultList();
        if (results != null) {
            Object id = results.get(0);
            if (id != null) {
                System.out.println(id.toString());
            }
        }
        em.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>
