title: JPA does not persist my class
body: <p>I am new to JPA and I am developing software with JPA 2.1.</p>
  
  <p>It creates the tables, run the code to save, does not appear any error with the JPA or Hibernate and when I read the same saved object, it is null</p>
  
  <p>My persistence.xml</p>
  
  <pre><code>&lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
  &lt;persistence-unit name="CLFockinkPU" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
      &lt;class&gt;br.ind.fockink.model.Cliente&lt;/class&gt;
      &lt;class&gt;br.ind.fockink.model.Funcionario&lt;/class&gt;
      &lt;class&gt;br.ind.fockink.model.Licenca&lt;/class&gt;
      &lt;class&gt;br.ind.fockink.model.PreCliente&lt;/class&gt;
      &lt;class&gt;br.ind.fockink.model.Terceiro&lt;/class&gt;
      &lt;class&gt;br.ind.fockink.model.Usuario&lt;/class&gt;
      &lt;properties&gt;
          &lt;!--  propriedades do hibernate --&gt;
          &lt;!-- Hibernate properties --&gt;
          &lt;property name="hibernate.show_sql" value="true" /&gt;
          &lt;property name="hibernate.format_sql" value="true" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
  
          &lt;!--  atualiza o banco, gera as tabelas se for preciso --&gt;
          &lt;property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@xxxxxxxxx:1521:XE"/&gt;
          &lt;property name="javax.persistence.jdbc.user" value="sys as sysdba"/&gt;
          &lt;property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/&gt;
          &lt;property name="javax.persistence.jdbc.password" value="xxxxx"/&gt;
  
  
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>My Class:</p>
  
  <pre><code>public class PreCliente implements Serializable {
  
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @SequenceGenerator(name = "WEB_SEQGRA2", sequenceName = "WEB_SEQGRA2", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "WEB_SEQGRA2")
    @Column(name = "ID_PRE_CLIENTE")
    private Long idPreCliente;
    @Column(name = "CPF")
    private String cpf;
    @Column(name = "CNPJ")
    private String cnpj;
    @Column(name = "RAZAO_SOCIAL")
    private String razaoSocial;
    @Basic(optional = false)
    @Column(name = "NOME_SOBRENOME")
    private String nomeSobrenome;
  </code></pre>
  
  <p>Generic DAO for persist:</p>
  
  <pre><code>public class GenericDAO&lt;PK, T&gt; {
    private EntityManager entityManager;
  
    public GenericDAO(EntityManager entityManager) {
        this.entityManager = entityManager;
    }
  
    public T getById(PK pk) {
        return (T) entityManager.find(getTypeClass(), pk);
    }
  
    public void save(T entity) {
        entityManager.persist(entity);
    }
  
    public void update(T entity) {
        entityManager.merge(entity);
    }
  
    public void delete(T entity) {
        entityManager.remove(entity);
    }
  
    public List&lt;T&gt; findAll() {
        return entityManager.createQuery(("FROM " + getTypeClass().getName()))
                .getResultList();
    }
  
    private Class&lt;?&gt; getTypeClass() {
        Class&lt;?&gt; clazz = (Class&lt;?&gt;) ((ParameterizedType) this.getClass()
                .getGenericSuperclass()).getActualTypeArguments()[1];
        return clazz;
    }
  </code></pre>
  
  <p>DAO Extend GenericDAO: </p>
  
  <pre><code>public class PreClienteDAO extends GenericDAO&lt;Long, PreCliente&gt; {
  
    public PreClienteDAO(EntityManager entityManager) {
        super(entityManager);
    }
  </code></pre>
  
  <p>And my test:</p>
  
  <pre><code>public static void main(String[] args) {
      // TODO code application logic here
      PreCliente pc = new PreCliente();
      pc.setCpf("123456789");
      pc.setNomeSobrenome("teste");
      PreClienteDAO dao = new PreClienteDAO(JPAUtil.getEntityManager());
      dao.save(pc);
  
      List&lt;PreCliente&gt; test = dao.findAll();
      System.out.println(test.get(0));
  }
  </code></pre>
  
  <p>Finaly, the hibernate return:</p>
  
  <pre><code>Hibernate: 
  create table PreCliente (
      ID_PRE_CLIENTE number(19,0) not null,
      CNPJ varchar2(255 char),
      CPF varchar2(255 char)
      NOME_SOBRENOME varchar2(255 char) not null,
      RAZAO_SOCIAL varchar2(255 char),
      primary key (ID_PRE_CLIENTE)
  )
  Hibernate: 
  create sequence WEB_SEQGRA2
  Hibernate: 
  select
      WEB_SEQGRA2.nextval 
  from
      dual
  Hibernate: 
  select
      precliente0_.ID_PRE_CLIENTE as ID_PRE_CLIENTE1_3_,
      precliente0_.CNPJ as CNPJ2_3_,
      precliente0_.CPF as CPF3_3_,
      precliente0_.NOME_SOBRENOME as NOME_SOBRENOME4_3_,
      precliente0_.RAZAO_SOCIAL as RAZAO_SOCIAL5_3_ 
  from
      PreCliente precliente0_
  </code></pre>
  
  <p>And the error for return anything:</p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  at java.util.ArrayList.rangeCheck(ArrayList.java:638)
  at java.util.ArrayList.get(ArrayList.java:414)
  at br.ind.fockink.clfockink.main(clfockink.java:31)  
  </code></pre>
  
  <p>Looking at the return of hibernate it seems that he is not saving the object correctly, but why?</p>