-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Batch inserts with EJB3/Hibernate/Annotations
PostPosted: Thu Aug 25, 2011 4:27 pm 
Newbie

Joined: Thu Aug 25, 2011 3:57 pm
Posts: 1
I've written an application that will read a CSV file and take the contents and for each line, a row is inserted into the database. However I can't seem to get the application to batch insert the objects. It's taking 20 minutes to load a 1.3MB file and an hour to do 2MB file(about 50k rows). Is

I've made sure that there's a JDBC batch size set. I've tried using an Oracle sequence for the ID since I've read that GenerationType.Identity won't work. I even tried setting the ID by hand and it still won't batch insert.

I've read the Hibernate batch page, but that mentions a SessionFactory and I don't see how to retrieve that since I have an entityManager.

What can I do to get this to batch insert the objects?

Thanks.

Below is a portion of my code.

Main application code:
Code:
System.out.println("Loading data in attachment");
Reader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");

CSVReader reader = new CSVReader(inputStreamReader);

ArrayList<String[]> csvFile = new ArrayList<String[]>();

String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
   csvFile.add(nextLine);
}

for (String[] fileLine : csvFile) {
   BigDecimal evaluatee = new BigDecimal(fileLine[0]);
   BigDecimal evaluator = new BigDecimal(fileLine[1]);
   
   if (evaluatee != null && evaluator != null) { //If we don't have both an evaluator and evaluatee, skip the line.
      nextRTAId = nextRTAId.add(BigDecimal.ONE);
      
      RecordsToAssign rta = new RecordsToAssign();
      rta.setId(nextRTAId);
      
      rta.setEvaluatee(evaluatee);
      rta.setEvaluator(evaluator);
      rta.persist();
   }
}


Object:
Code:
@Configurable
@Entity
@Table(name = "RECORDSTOASSIGN")
public class RecordsToAssign {
   @PersistenceContext
    transient EntityManager entityManager;

   @Id
   @Column(name = "ID")
    private BigDecimal id;
   
   @Column(name = "EVALUATEEDSID")
    private BigDecimal evaluatee;
   
    @Column(name = "EVALUATORDSID")
   private BigDecimal evaluator;
   
   @Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }
}   


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.