Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Hibernate/JBoss & Bulk Insert?

Thread Tools

Re: Hibernate/JBoss & Bulk Insert?

Posts: n/a
Thanks for your reply. However, I would still like a way to use Hibernate for bulk inserts, if possible, since I'm trying to improve
the performance of a web app. Although straight JDBC, etc. may be faster, the database tables use primary keys that are auto
incremented and this can cause a problem using JDBC when multiple users can concurrently make inserts into the database.

In addition, I do have a program that will create a file that I can import into MySQL that runs very fast.


BTW, I know that the database doesn't store objects. That's why an ORM (i.e., Hibernate) is being used to bridge Java and a
relational database.

From: "Owen Jacobson" <(E-Mail Removed)>
Subject: Re: Hibernate/JBoss & Bulk Insert?
Date: Monday, September 15, 2008 5:47 PM

On Sep 15, 3:43 pm, "Steve" <(E-Mail Removed)> wrote:
> I am looking for a way to do a bulk insert of thousands of objects using JBoss and Hibernate. I currently have an injected
> EntityManager with a JTA PersistenceContext in a Stateless Session Bean and am doing something like
> for(int i = 0; i < num; i++){
> MyObject myObject = createMyObject(num, ...);
> entityManager.persist(myObject);
> }
> (in a try/catch block) which is slow.
> I have unsuccessfully tried to use entityManager.getTransaction() to begin, commit, etc. transactions. I have also unsuccessfully
> tied to convert the EntityManager to a HibernateEntityManager and use Hibernate transactions. I've also tried to use
> @TransactionAttribute(TransactionAttributeType.REQ UIRED) but it made no significant difference (it's slightly faster).
> Is there a way to save multiple objects in a "single" database call, or at least a few?
> BTW, Having something like entityManager.persist(collection) would be nice.

You'll get much better performance for bulk operations by realizing
that your database *does not store Objects*, just rows, and treating
data appropriately. In this case, iBATIS or straight JDBC will
probably be much, much faster than JPA, as you can skip all of the
steps involved in converting your data to objects and back to data.
In fact, you may be better off skipping the app entirely and using
your DB's equivalent of COPY <tablename> or LOAD <tablename> to bulk-
load data from a flat file...


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk Edit in datagrid. =?Utf-8?B?U2lyaXNoYQ==?= ASP .Net 0 03-21-2006 06:39 PM
Bulk Import - Thread was being Abort Prasad Dannani ASP .Net 0 09-01-2005 06:32 PM
Re: Bulk Newsgroup Poster - amazing result Malke Wireless Networking 0 01-17-2005 01:35 AM
Bulk edit in DataGrid Stan ASP .Net 1 08-12-2003 10:08 PM
bulk loading with DBI Greg H Perl 1 07-17-2003 02:52 PM