users@glassfish.java.net

SEQUENCE JPA commit

From: <glassfish_at_javadesktop.org>
Date: Mon, 12 Nov 2007 10:56:56 PST

Hi,

I have a bit of a problem using Toplink Essentials, a table based sequence generator, and the Derby(JavaDB) database.

The issue is that I create and persist a large number of objects whose ID is automatically generated. So the code for the entity class is like:

@Entity
public class JohnDoe {
        @Id
        @TableGenerator(name="JD_SEQ_GEN", table="ID_GEN",
                    pkColumnName="JD_NAME", valueColumnName="SEQ_COUNT",
                    pkColumnValue="JD_SEQ_GEN", allocationSize=1, initialValue = 1)
        @GeneratedValue(generator="JD_SEQ_GEN")
        private int jdid;

        ...
}

For clarification, those @GeneratedValue and @TableGenerator annotations allow Toplink Essentials to generate an automatic primary key id based on an entry in the table ID_GEN.

Now here's the issue, when I start persisting objects, the process is very slow but is not CPU or memory limited. When I enable logging on the database, I see a very large number of select statements such as:

2007-11-12 16:54:33.855 GMT Thread[DRDAConnThread_13,5,main] (XID = 14076), (SESSIONID = 12), (DATABASE = PeaksDB), (DRDAID = NF000001.D413-1012464296341916660{13}), Executing prepared statement: SELECT SEQ_COUNT FROM ID_GEN WHERE SEQ_NAME = ? :End prepared statement with 1 parameters begin parameter #1: SPEC_SEQ_GEN :end parameter

2007-11-12 16:54:33.856 GMT Thread[DRDAConnThread_13,5,main] (XID = 14076), (SESSIONID = 12), (DATABASE = PeaksDB), (DRDAID = NF000001.D413-1012464296341916660{13}), Committing

This seems to indicate that the database is doing disk-based IO to commit every update to the sequence number when I retrieve a new one for the next spectrum object!

Thus, the process is quite slow.
Is there anyway of caching the sequence number operations or something similar in order to avoid this rather hefty slowdown?

Thanks
[Message sent by forum member 'mucushernia' (mucushernia)]

http://forums.java.net/jive/thread.jspa?messageID=245084