0

最近,当我使用 EclipsLink 2.0 时,我在实现持久对象时遇到了性能瓶颈问题。

更具体地说,我曾经有以下实现:

@Entity
@Table(name = "CUSTOMERS")
public class CustomerEntity implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private volatile Long id;

@Column(nullable = false, unique = true)
private String name;

private static final long  serialVersionUID = 6952530957072210017L;

private String custGroup;
private String address;
private String nameOfFirstPerson;
private String contactPerson;
private String phone;
private String fax;
private String email;
private String comments;
private String defaultCustomer;
private volatile boolean delayedPaymentAllowed;
private volatile long periodOfDelayedPaymentAllowed;
private volatile boolean restrictionsOnDelayedPayment;
private volatile double maxAmoutPemittedSom;
private volatile double maxAmoutPemittedYE;
private transient String salesPointName;

@Column(length=25483)
private HashMap<String, PriceItem> totalBalance;

@Column(length=25483)
private HashMap<String, PriceItem> totalBalanceUsd;

private transient boolean valueChanged = false;


@OneToMany(mappedBy = "supplier")
private Collection<PurchaseInvoiceEntity> purchaseInvoices;

@OneToMany(mappedBy = "receiver")
private Collection<SalesInvoiceEntity> salesInvoices;

@OneToMany(mappedBy = "payer")
private Collection<PayInSlipEntity> payInSlips;

@OneToMany(mappedBy = "recipient")
private Collection<PaymentOrderEntity> paymentOrders;

@OneToMany(mappedBy = "recipient")
private Collection<WriteOffEntity> writeOffs;

@ManyToOne()
private ResponsiblePersonForDebtEntity responsiblePersonForDebt;

@ManyToOne
private CustomerGroupEntity customerGroup;


public CustomerEntity() {

    valueChanged = false;
}
...
}

并且每次我在将新文档实例插入表格时将新文档实例添加到适当的集合中时,我都检测到插入文档所需的时间太长。我在使用 netbeans ide 6.9 的分析器模块时遇到了这个问题。实际上,我正在使用这些集合来检查相关文档是否为空。

4

2 回答 2

0

为了解决这个问题,我简单地应用了以下解决方案:

  1. 我只是删除了文档引用:

    @OneToMany(mappedBy = "supplier") 私人收藏 purchaseInvoices;

    @OneToMany(mappedBy = "receiver") 私人收藏 salesInvoices;

    @OneToMany(mappedBy = "payer") 私人收藏 payInSlips;

    @OneToMany(mappedBy = "recipient") 私人收藏 paymentOrders;

    @OneToMany(mappedBy = "recipient") 私人收藏注销;

来自客户实体:

 @Entity

@Table(name = "CUSTOMERS") 公共类 CustomerEntity 实现可序列化 {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private volatile Long id;
@Column(nullable = false, unique = true)
private String name;
private static final long serialVersionUID = 6952530957072210017L;
private String custGroup;
private String address;
private String nameOfFirstPerson;
private String contactPerson;
private String phone;
private String fax;
private String email;
private String comments;
private String defaultCustomer;
private volatile boolean delayedPaymentAllowed;
private volatile long periodOfDelayedPaymentAllowed;
private volatile boolean restrictionsOnDelayedPayment;
private volatile double maxAmoutPemittedSom;
private volatile double maxAmoutPemittedYE;
private transient String salesPointName;
@Column(length = 25483)
private HashMap<String, PriceItem> totalBalance;
@Column(length = 25483)
private HashMap<String, PriceItem> totalBalanceUsd;
private transient boolean valueChanged = false;
@ManyToOne()
private ResponsiblePersonForDebtEntity responsiblePersonForDebt;
@ManyToOne
private CustomerGroupEntity customerGroup;

public CustomerEntity() {

    valueChanged = false;
}
 .....}
  1. 在检查文档的引用时,我在编辑或删除 CustomerEntity 时使用了 JPA 查询。

这个简单的更改消除了影响最大的性能问题。

边注:

请在使用性能分析器时也包括对包方法的检查(例如,eclipslink)

于 2012-07-20T09:40:37.427 回答
0

有关 JPA 中的性能和可伸缩性问题,请阅读或收听 Gordon Yorke 的“高度可伸缩 Java 持久性应用程序的策略和最佳实践”。

于 2012-10-05T13:15:21.910 回答