0

I'm using jpa (hibernate) and I'm trying to make several insert then I'm going to use batch but I have the following problem: Hibernate only makes all insert in the final of process. I'm using jpa (hibernate 4), ejb 3.1, jboss eap 6.1, JTA ans Postgresql

<persistence-unit name="VSDialerUnit" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/VSDialer</jta-data-source>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.jdbc.batch_size" value="50"/>
        <property name="hibernate.jdbc.fetch_size" value="50"/>
    </properties>
</persistence-unit>

public void inserirBatch(T objeto, Integer quantidade){
    entityManager.persist(objeto);
    if(quantidade % 50 == 0){
        limparEntityManager();
    }
}

public void limparEntityManager(){
    entityManager.flush();
    entityManager.clear();
}
Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
  • Batching won't do you much good with PgJDBC anyway, it doesn't do anything useful with batched SQL. If you're trying to do bulk inserts, use `COPY` via the PgJDBC `CopyManager` instead. See also http://stackoverflow.com/q/12206600/398670 – Craig Ringer Feb 05 '14 at 12:30
  • I have to read with csv file with my java web application and process it, I was looking for COPY, is it possible to use COPY with 2 tables? – Alisson Vieira Feb 05 '14 at 15:14
  • No idea what you mean. `COPY` once for each input CSV to each target table seems like the obvious answer. If that's not it, explain further please. – Craig Ringer Feb 06 '14 at 03:27

0 Answers0