Home » Eclipse Projects » EclipseLink » Need help configuring EclipseLink JPA
Need help configuring EclipseLink JPA [message #386074] |
Fri, 27 March 2009 21:02 |
andiqo Messages: 32 Registered: July 2009 |
Member |
|
|
I need help configuring EclipseLink JPA. Sorry but I am very new to
EclipseLink...
I have a test case which simply commit 11 110 entities in datastore but it
is very slow, and I don't understand why...
** End 1st gen (10) done in 0.053765492s
** End 2nd gen (100) done in 1.397968667s
** End 3rd gen (1000) done in 6.498315777s
** End 4th gen (10000) done in 367.321999793s
Same test execution using OpenJpa (15s vs 375s !) :
** End 1st gen (10) done in 0.049514742s
** End 2nd gen (100) done in 0.33861224s
** End 3rd gen (1000) done in 3.152090838s
** End 4th gen (10000) done in 11.539020043s
I am using EclipseLink 2.0.0M1.
Below my entities and my persistence.xml file (very simple at the moment).
Thanks for your help!
andiqo
@Entity
@Table(name = "NODE")
public class Node implements ICopyable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private long id;
@Version
@Column(name = "VERSION")
private int version;
@OneToMany(mappedBy = "to", fetch = FetchType.LAZY, cascade =
CascadeType.ALL, orphanRemoval = true)
private Set<Edge> inputs = new HashSet<Edge>();
@OneToMany(mappedBy = "from", fetch = FetchType.LAZY, cascade =
CascadeType.ALL, orphanRemoval = true)
private Set<Edge> outputs = new HashSet<Edge>();
}
@Entity
@Table(name = "EDGE")
public class Edge {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private long id;
@Version
@Column(name = "VERSION")
private int version;
/** The parent */
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "FROM_ID", nullable = false, updatable = false)
private Node from;
/** The target */
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "TO_ID", nullable = false, updatable = false)
private Node to;
}
persistence.xml
<properties>
<!-- Database -->
<property name="eclipselink.target-database" value="Auto"/>
<!-- Connection -->
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://localhost:5432/jenmo?compatible=7.1" />
<property name="javax.persistence.jdbc.driver"
value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="dbadmin" />
</properties>
|
|
|
Re: Need help configuring EclipseLink JPA [message #386075 is a reply to message #386074] |
Sun, 29 March 2009 10:45 |
andiqo Messages: 32 Registered: July 2009 |
Member |
|
|
Sorry for the bad formatting in my previous post:
EclipseLink (persisting 11 110 Nodes):
** End 1st gen (10) done in 0.053765492s
** End 2nd gen (100) done in 1.397968667s
** End 3rd gen (1000) done in 6.498315777s
** End 4th gen (10000) done in 367.321999793s
OpenJpa (persisting 11 110 Nodes):
** End 1st gen (10) done in 0.049514742s
** End 2nd gen (100) done in 0.33861224s
** End 3rd gen (1000) done in 3.152090838s
** End 4th gen (10000) done in 11.539020043s
Do you have an idea what could cause such a difference between OpenJpa and
EclipseLink?
Two differences I have noticed :
* In my Java code
OpenJpa :
OpenJPAEntityManager.persistAll
EclipseLink
for (Object o : pcs) {
em.persist(o);
}
* In the generated SQL
OpenJpa:
SELECT CURRVAL('EDGE_ID_seq')
INSERT IGNORE INTO EDGE (CASCADED, IDX, KIND, VERSION, TO_ID, FROM_ID) VALUES (?,
?, ?, ?, ?, ?) [params=(boolean) true, (null) null, (int) -1, (int) 1,
(long) 1057, (long) 32]
EclipseLink:
select lastval()
INSERT IGNORE INTO EDGE (IDX, CASCADED, KIND, VERSION, FROM_ID, TO_ID) VALUES (?,
?, ?, ?, ?, ?)
bind => [null, true, -1, 1, 5, 101]
Don't know exactly if lastval() use PostgreSQL sequences...
Thanks for your help.
andiqo
P.S. I have set <property name="eclipselink.jdbc.native-sql"
value="true"/> in my persistence.xml
|
|
| |
Re: Need help configuring EclipseLink JPA [message #386078 is a reply to message #386074] |
Mon, 30 March 2009 14:39 |
|
This is odd, as the performance testing we have done against OpenJPA has
been very favorable towards EclipseLink. From you summer it seems this
issue is you are using SEQUENCE based sequencing in OpenJPA but IDENTITY
in EclipseLink.
Postgres supports both IDENTITY and SEQUENCE sequencing. SEQUENCE
sequence is always recommended as it support preallocation. I would never
recommend IDENTITY sequencing as it does not support preallocation, so can
be a major performance issue. My guess as to what is occurring is that
OpenJPA only support SEQUENCE sequencing it is defaulting the IDENTIY to
SEQUENCE, where as EcliseLink supports both IDENTITY and SEQUENCE, so is
using IDENTITY. So change your classes to use SEQUENCE instead of
IDENTITY.
Also ensure you are using the EclipsLink agent and it is running properly.
Other optimization I would recommend for this case are:
Set,
"eclipselink.jdbc.batch-writing"="JDBC"
"eclipselink.jdbc.batch-writing.size"="1000"
"eclipselink.jdbc.cache-statements"="true"
Also since this seems to be a pure insert test, I would recommend turning
the cache off, or at least off for the class being inserted.
"eclipselink.cache.shared.default"="false"
Note that "eclipselink.jdbc.native-sql" does nothing, as it only effect
how parameters are printed, and parameter binding is the default.
In EclipseLink 1.1 there are also some lower level optimizations. If you
are creating a new EntityManager per transaction, you can use,
"eclipselink.persistence-context.close-on-commit"="true"
This avoids resuming costs.
If you are still having issues please include the full code to how you are
creating your objects and persisting them, how you are creating and
committing your EntityManager, and the full SQL. Your results still seem
odd because they seem to be non-linear. Are the objects that you are
persisting all related? You have cascade persist set, so persist requires
to traverse all related objects. If all of your objects are related and
you call persist on each one, then this is a n^2 issue, the JPA spec
requires this, but perhaps OpenJPA does not obey the spec in this case.
You should either remove the cascade persist, or only call persist on the
root object.
---
James
http://www.nabble.com/EclipseLink---Users-f26658.html
James : Wiki : Book : Blog : Twitter
|
|
| | |
Goto Forum:
Current Time: Sat Jan 25 17:12:42 GMT 2025
Powered by FUDForum. Page generated in 0.03413 seconds
|