2016-12-29 19 views
1

我使用JavaEE7,休眠,jpa2.1
我的項目有太多的實體(約2000單位)
如果只有100對象實體,它啓動正常。
但現在我已經添加了我所有的業務實體類(2000年),我得到一個pergem空間誤差。
當JPA休眠掃描太多的實體,GlassFish的啓動速度很慢或memorry泄漏

2016-12-29T11:40:36.903+0700|Severe: Exception in thread "DynamicReloader" 
    2016-12-29T11:40:36.904+0700|Severe: java.lang.OutOfMemoryError: GC overhead limit exceeded 
    2016-12-29T11:40:37.899+0700|Severe: Exception in thread "AutoDeployer" 
    2016-12-29T11:40:37.900+0700|Severe: java.lang.OutOfMemoryError: GC overhead limit exceeded 

我已經提高JVM的內存參數,但現在我的應用程序是在啓動時非常慢。
所以,我想知道,如果有一些選項,更快地加載此實體? 預先感謝

這是例如實體

@Entity 
@Table(name = "TBL_USER") 
@NamedQueries({ 
     @NamedQuery(name = "TblUserO.findAll", query = "SELECT t FROM TblUserO t") 
}) 
public class TblUserO implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "USER_ID", unique = true, nullable = false, precision = 11) 
    private Long userId; 

的persistence.xml

 <persistence-unit name="c1spostgre1" transaction-type="JTA"> 
     <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 
     <jta-data-source>jdbc/__PSG1</jta-data-source> 
     <!-- Named JPQL queries per entity, but any other organization is possible --> 
     <properties> 
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/> 
      <property name="hibernate.enable_lazy_load_no_trans" value="true"/> 
      <!-- <property name="hibernate.archive.autodetection" value="class" /> --> 
      <property name="hibernate.show_sql" value="true" /> 
      <property name="hibernate.format_sql" value="true" /> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL92Dialect" /> 
      <property name="hibernate.jdbc.batch_size" value="20" /> 
      <property name="hibernate.order_updates" value="true"/> 
      <property name="hibernate.order_inserts" value="true"/> 
     </properties> 
    </persistence-unit> 
    <persistence-unit name="c1spostgre2" transaction-type="JTA"> 
     <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 
     <jta-data-source>jdbc/__PSG2</jta-data-source> 
     <properties> 
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/> 
      <property name="hibernate.enable_lazy_load_no_trans" value="true"/> 
      <!-- <property name="hibernate.archive.autodetection" value="class" /> --> 
      <property name="hibernate.show_sql" value="true" /> 
      <property name="hibernate.format_sql" value="true" /> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL92Dialect" /> 
      <property name="hibernate.jdbc.batch_size" value="20" /> 
      <property name="hibernate.order_updates" value="true"/> 
      <property name="hibernate.order_inserts" value="true"/> 
     </properties> 
    </persistence-unit> 

回答

0

你已經增加了堆內存(不PermGen的)足以使你的應用程序現在可以啓動,但這麼多需要加載到內存中,你幾乎可以肯定地做大量的垃圾收集,而所有這些都會被加載,這將導致放緩。這聽起來像需要對應用程序進行廣泛的性能調整,但這遠遠超出了StackOverflow問題的範圍。

0

看來,在啓動時從數據庫應用程序中加載太多的數據。我的猜測是,額外的實體有太多的渴望關係,並且你的應用程序爲它需要做的事情加載了太多不必要的數據。

我建議審查實體映射,減少許多關係到懶惰地(尤其是*一對多的關係,都應該延遲訪,這是默認的)。爲了搜索加載了哪些不必要的數據,可以打開SQL查詢的日誌記錄以檢測用於存放數據的SQL腳本。您的應用程序可能會將某些表中的所有實體加載到內存中,並在稍後進行過濾,但效率不高。

你應該重新考慮把過濾到JPQL查詢。你也應該減少的findAll查詢的使用,或者至少調用getResultList()之前限制檢索到的實體的數量與setMaxResult()