Java Swing / JPA / Oracle inserting twice -


Maybe a newbie java ... but here it is. Using JPA to call INSERT stored procedure in an Oracle 11g database, everything works fine in the case of receiving data in the DB table

I have wrapped the JPA code in the Java Swing application. The problem is that the data gets stored in some way or in some other form twice. I have a joypaypanpan.shows mezeidiog shows when I submit data only shows it once. But when I ask the table, there are two entries in the table. Here is my code ....

Button Code

  Jebton BTsSubmit = New PayButton ("Submit"); BtnSubmit.addActionListener (New Exhibitist) {Public Zero Action Perfid (ActionAgeRGET) {AddNewCustomer ();}}); BtnSubmit.setBounds (24, 341, 91, 23); Add frmNewCustomer.getContentPane () (btnSubmit) .;  

Action Methods

  Public Zero AddNewCustomer () {Customer. AddCustomer (this.txtFirstName.getText (), it.txtLastName.getText (), this.txtAddress.getText (), this.txtCity.getText (), this.txtState.getText (), this.txtEmail.getText (), This.txtPhone.getText ()); Employmentpan Shmose's Diagonal (FRM nucleus, "new customer added", "condition", 1); } Protected static void AddCustomer (string sFirstName, string sLastName, string sAddress, string sCity, string sSTate, string sEmail, string sPhone) {try {factory = stubborn .createEntityManagerFactory (PERSISTENCE_UNIT_NAME); EntityManager em = factory.createEntityManager (); Em.getTransaction () start () .; Query q = em.createNamedQuery ("AddCustomer"); Q.setParameter ("p_PHONE", Sphone); Q.setParameter ("p_STATE", asstate); Q.setParameter ("p_FIRST_NAME", sFirstName); Q.setParameter ("p_ADDRESS", SADrace); Q.setParameter ("p_EMAIL", sEmail); Q.setParameter ("p_CITY", sCity); Q.setParameter ("p_LAST_NAME", sLastName); Int r = q.executeUpdate (); Committed to em.getTransaction (). List Result = q.getResultList (); If (result! = Null) {object id = results.get (0); If (id! = Null) {System.out.println (id.toString ()); }} Em.close (); } Hold (exception e) {e.printStackTrace (); }}  

You need to delete the call to getResultList () , it is executing the same query again (and this is a insert query, not a select query). You should not need to get an ID in any way, see. You should use an entry in the form of an appropriate way of creating an entry but this does not need to use a question for entityManager.persist (obj) (assuming you have it for A JPA unit, you should do that since you are using JPA anyway).


Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -