I'm trying to persist a lot of data but I always got a "memoryOutException". I already tried flush, clear, close... everything that every kind of solution presented here in SOF.. and none worked, my memory keep growing and the persist/commit is going on slower and slower...
public class Insersecao1 {
private static EntityManagerFactory emf;
private static SessionFactory factory;
public static void main(final String[] args) throws Exception {
File pathFile = new File("D:\\Dados lab\\Database-json");
AnalyzedCommit analyzedCommit = null;
emf = Persistence.createEntityManagerFactory("hikePu");
EntityManager entityManager = emf.createEntityManager();
entityManager.getTransaction().begin();
int count = 1;
for (File f : pathFile.listFiles()) {
analyzedCommit = ... ;
entityManager.persist(analyzedCommit);
if (count % 75 == 0) {
entityManager.getTransaction().commit();
entityManager.close();
entityManager = emf.createEntityManager(); //Tried create a new one
entityManager.getTransaction().begin();
}
count++;
System.out.println(count);
}
} }
using on maven:
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-neo4j</artifactId>
<version>5.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossts</groupId>
<artifactId>jbossjta</artifactId>
<version>4.16.6.Final</version>
</dependency>
And Persist:
<persistence-unit name="hikePu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="hibernate.ogm.datastore.provider" value="neo4j_embedded" />
<property name="hibernate.ogm.datastore.database" value="EasyDB" />
<property name="hibernate.ogm.neo4j.database_path" value="D:\Dados lab\mydb" />
<!-- <property name="hibernate.ogm.neo4j.database_path" value="mydb" />-->
<property name="dbms.allow_format_migration" value="true" />
</properties>
</persistence-unit>
As far as I can see from my profiling, it comes from Neo4j, not from OGM. Using an external Neo4j server allows to see that the OGM memory usage is stable (I'm running an insert of 8 millions entities right now).
I would suggest you upgrade to Hibernate OGM 5.1.0.Final and use an external Neo4j server either with the neo4j_http datastore provider or the neo4j_bolt datastore protocol (I would recommend to use Bolt).
I think it's a better solution anyway as you would have access to the nice Neo4j console and so on.
See https://docs.jboss.org/hibernate/stable/ogm/reference/en-US/html_single/#_configuring_neo4j for more information about how to configure the access to your Neo4j server.