// Copyright (c) 2015 Olaf Dietsche

//package de.olafdietsche.jpa.hello_world;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.persistence.Table;

@Entity
@Table(name = "contacts")
class Contact {
	@Id
	public int id;
	public String name;
	public String email;
	public String phone;
}

public class HelloWorld {
	public static Contact createContact(int id, String name, String email, String phone) {
		Contact contact = new Contact();
		contact.id = id;
		contact.name = name;
		contact.email = email;
		contact.phone = phone;
		return contact;
	}

	public static void main(String[] args) {
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("ContactManagement");
		EntityManager em = emf.createEntityManager();
		EntityTransaction tx = em.getTransaction();

		tx.begin();

		Contact contact = createContact(7, "John Doe", "john@example.com", "555-123-4567");
		em.persist(contact);
		em.flush();
		tx.commit();

		tx.begin();
		Query insert = em.createNativeQuery("insert into contacts(id, name, email, phone) values(?, ?, ?, ?)");
		insert.setParameter(1, 8);
		insert.setParameter(2, "Jane Doe");
		insert.setParameter(3, "jane@example.com");
		insert.setParameter(4, "555-456-7890");
		insert.executeUpdate();
		tx.rollback();

		em.close();
		emf.close();
	}
}

@@ -267,16 +267,107 @@
 action;%0A
+import javax.persistence.GeneratedValue;%0Aimport static javax.persistence.GenerationType.*;%0A
 import j
@@ -516,16 +516,54 @@
  %7B%0A%09@Id%0A
+%09@GeneratedValue(strategy = SEQUENCE)%0A
 %09public 
@@ -705,16 +705,8 @@
 act(
-int id, 
 Stri
@@ -783,27 +783,8 @@
 ();%0A
-%09%09contact.id = id;%0A
 %09%09co
@@ -1154,11 +1154,8 @@
 act(
-7, 
 %22Joh
@@ -1330,12 +1330,8 @@
 cts(
-id, 
 name
@@ -1358,19 +1358,16 @@
 es(?, ?,
- ?,
  ?)%22);%0A%09
@@ -1393,37 +1393,8 @@
 r(1,
- 8);%0A%09%09insert.setParameter(2,
  %22Ja
@@ -1425,17 +1425,17 @@
 rameter(
-3
+2
 , %22jane@
@@ -1471,17 +1471,17 @@
 rameter(
-4
+3
 , %22555-4

Use auto_increment for id column