0

我使用带有 Eclipse 链接 2.3 和 Derby db 的实体管理器 JPA,我有 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

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

我注意到当我删除这两个实体时,时间节省了 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; }

}
4

1 回答 1

2

这里概述了许多性能优化,

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 条批次并获得 12 秒而不是 70 秒。70 年代听起来您正在处理某种 n^2 问题。

于 2013-04-30T13:05:46.310 回答