openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kuuldor <>
Subject Weird Performance Problem
Date Mon, 21 Jan 2008 14:27:16 GMT
Hi everybody,
I'm trying to use OpenJPA in my new project, but when I do some
experiments I encounter a very low performance in inserting records
into database.

My situation is like this:
Database is derby 10.2
A very simple table 'account' having a auto-increment ID, and a 'name'
field of varchar(16), and an 'fullname' field of varchar(32) and
'descript' of varchar(255).
Here is the create table SQL:
create table account (id integer not null generated always as
identity, name varchar(16) not null unique, fullname varchar(32),
descript varchar(255), constraint Account_Primary_ID primary key
My persistence.xml is like this:
<persistence xmlns=""
 <persistence-unit name="Test" transaction-type="RESOURCE_LOCAL">
    <property name="openjpa.ConnectionDriverName"
    value="org.apache.derby.jdbc.ClientDriver" />
   <property name="openjpa.ConnectionURL"
    value="jdbc:derby://localhost:1527/tsam2" />
   <property name="openjpa.ConnectionUserName" value="app" />
   <property name="openjpa.ConnectionPassword" value="app" />
   <property name="openjpa.Log" value="none" />
   <property name="openjpa.DataCache" value="true" />
   <property name="openjpa.RemoteCommitProvider" value="sjvm" />

And the Entity Class is:
package test;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.persistence.*;

public class Account  implements Serializable {
 //default serial version id, required for serializable classes.
 private static final long serialVersionUID = 1L;
 private Integer id;
 private String descript;
 private String fullname;
 private String name;

    public Account() {

 @Column(name="ID", unique=true, nullable=false, precision=10)
 public Integer getId() {
 public void setId(Integer id) { = id;

 @Column(name="DESCRIPT", length=255)
 public String getDescript() {
  return this.descript;
 public void setDescript(String descript) {
  this.descript = descript;

 @Column(name="FULLNAME", length=32)
 public String getFullname() {
  return this.fullname;
 public void setFullname(String fullname) {
  this.fullname = fullname;

 @Column(name="NAME", unique=true, nullable=false, length=16)
 public String getName() {
 public void setName(String name) { = name;

 public boolean equals(Object other) {
  if (this == other) {
   return true;
  if (!(other instanceof Account)) {
   return false;
  Account castOther = (Account)other;
  return new EqualsBuilder()
   .append(this.getId(), castOther.getId())

 public int hashCode() {
  return new HashCodeBuilder()

 public String toString() {
  return new ToStringBuilder(this)
   .append("id", getId())

My test is to insert 1000 records into the table. The test code is like this:
 private static void insertJPA() throws DAOException, SQLException {
  DAOFactory daoF = new DAOFactory();
  AccountDao accountDao = daoF.getAccountDao();
  System.out.println(new java.util.Date().toString());

  for (int i = 0; i<1000; i++)

   TransactionProxy tran = accountDao.beginTransaction();
   Account newuser = new Account();
   newuser.setName("user" + i);
   //newuser.setFullname("User No. " + i);
   //newuser.setDescript("Common user");

This test can only finish in about 1min 30sec, equals to 11rec/sec. If
I get rid of the fullname and descript fields from the table. The time
can be shorten to 32sec. But it still be quite slow. I've done the
test with BEA Kodo which is based on OpenJPA. Kodo can insert the 1000
record in 9sec, about 10 times faster than OpenJPA. And I did not do
any optimization for Kodo.

So anybody knows why the performance of OpenJPA is so slow? Or how to
optimize OpenJPA to achieve the performance near Kodo?

Thanks a lot.

View raw message