2013-04-30 38 views
1

使用实体管理器JPA与eclipse链接2.3 & Derby db和我有10个实体的模型和我需要存储的每个实体1000个记录,这个过程大约70秒。我已经测试了10个实体的同一个模型,但是使用100个记录提交的所有过程花费大约1.2秒,这非常棒。实体管理器提交的性能不佳 - 指数

瓶颈是entityManager.getTransaction().commit();我坚持所有的数据后,我只做了一次,承诺从所有过程中获得更多的95%。 当我使用JVM监视我潜水的承诺,我看到这个类的一个负责几乎所有的提交时间,该类是org.eclipse.persistence.mappings.ManyToManyMapping

http://www.eclipse.org/eclipselink/api/1.0/org/eclipse/persistence/mappings/ManyToManyMapping.html

我的实体和模型没有按” t有任何多对多的关系或使用任何很多的注释,什么可能是指数行为的原因?

我注意到,当我删除这两个实体的时间节省了85%

什么是错的这个实体

导航是从一个人具有基数1到标题奖是有基数N个即一个人可以有多个奖项...

@javax.persistence.Entity 
@javax.persistence.Table(name = "a3_Person") 
public class Person { 
    @javax.persistence.Id 
    @javax.persistence.Column(length = 20)  
    //// Id; 
    private String person_id; 
    public String getPerson_id() { return this.person_id; } 
    public void setPerson_id(String person_id) { this.person_id = person_id; } 

    @javax.persistence.Column(length = 30)  
    //// Name; 
    private String person_name; 
    public String getPerson_name() { return this.person_name; } 
    public void setPerson_name(String person_name) { this.person_name = person_name; } 

    //// Awards; 
    private List<TitleAward> person_awards; 
    public List<TitleAward> getPerson_awards() { return this.person_awards; } 
    public void setPerson_awards(List<TitleAward> person_awards) { this.person_awards = person_awards; } 

} 




@javax.persistence.Entity 
@javax.persistence.Table(name = "a3_TitleAward") 
public class TitleAward { 
    @javax.persistence.Id 
    @javax.persistence.Column(length = 20)  
    //// Id; 
    private String titleaward_id; 
    public String getTitleaward_id() { return this.titleaward_id; } 
    public void setTitleaward_id(String titleaward_id) { this.titleaward_id = titleaward_id; } 

    @javax.persistence.Column(length = 30)  
    //// Type; 
    private String titleaward_type; 
    public String getTitleaward_type() { return this.titleaward_type; } 
    public void setTitleaward_type(String titleaward_type) { this.titleaward_type = titleaward_type; } 

    @javax.persistence.Column(length = 30)  
    //// Category; 
    private String Cateeheihbadc; 
    public String getCateeheihbadc() { return this.Cateeheihbadc; } 
    public void setCateeheihbadc(String Cateeheihbadc) { this.Cateeheihbadc = Cateeheihbadc; } 

    @javax.persistence.Column()  
    //// Year; 
    private String titleaward_year; 
    public String getTitleaward_year() { return this.titleaward_year; } 
    public void setTitleaward_year(String titleaward_year) { this.titleaward_year = titleaward_year; } 

    @javax.persistence.Column()  
    //// Won; 
    private Boolean titleaward_won; 
    public Boolean getTitleaward_won() { return this.titleaward_won; } 
    public void setTitleaward_won(Boolean titleaward_won) { this.titleaward_won = titleaward_won; } 

    //// Person; 
    private Person Pers_fhfgdcjef; 
    public Person getPers_fhfgdcjef() { return this.Pers_fhfgdcjef; } 
    public void setPers_fhfgdcjef(Person Pers_fhfgdcjef) { this.Pers_fhfgdcjef = Pers_fhfgdcjef; } 

} 

回答

2

有概述了一些性能优化^ h ERE,

http://java-persistence-performance.blogspot.com/2011/06/how-to-improve-jpa-performance-by-1825.html

ManyToManyMapping还用于为使用@JoinTable,您使用这个@OneToMany批注?一般来说,正确分析和理解配置文件可能很困难,因此您的配置文件可能无效。

请包括您的代码以及SQL日志和配置文件的示例。您也可以启用的EclipseLink PerformanceMonitor,

看到, http://www.eclipse.org/eclipselink/documentation/2.4/concepts/monitoring003.htm

如果有100条记录只需要1.2秒,那么你很可能打破你的过程变成100批次,获得12S,而不是70年代。 70年代听起来像你有某种n^2问题正在进行。

+0

谢谢詹姆斯!我已经添加了两个实体(我编辑了这两个实体的帖子),这些问题可以让你看到什么是错误的定义,因为我有不同的实体与1到N,在同一个模型中不会导致性能不佳, – 2013-04-30 14:25:07

+2

嗯,你有一个ManyToMany,person_awards,因为这是任何实体集合的默认值。你应该使用@OneToMany(mappedBy =“Pers_fhfgdcjef”)。但要知道性能问题是什么,您需要包含您正在运行的代码以及SQL日志或配置文件的样本。 – James 2013-05-01 13:04:26

+0

@ James- im使用netfilix文件有同样的问题。它实际上是什么意思,实际上,如果你不添加注释实体与列表JPA翻译它默认多对多?btw你怎么看到这个文件在吉恩帖子有很多很多?谢谢! – 2013-05-01 15:39:57