2013-03-10 42 views
0

我得到ModPm類Hibernate的懶加載沒有奏效

@Entity 
    @Table(name="MOD_PM") 
    public class ModPm extends WebPageObject implements Serializable, IDBNamedEntity { 

     private static final long serialVersionUID = 1L; 

     public final static String Q_GET_DEPENDENT_LIST_FOR_NEW_SCOPE = "ModPm.getDependentForNewScope"; 
     public final static String Q_GET_DEPENDENT_LIST_WITHOUT_STATUS_FOR_SCOPE = "ModPm.getDependentWithoutStatusForScope"; 
     public final static String Q_GET_STATUS_FOR_NEW_SCOPE = "ModPm.getStatusForNewScope"; 
     public final static String Q_GET_WITHOUT_STATUS_FOR_SCOPE = "ModPm.getWithoutStatusForScope"; 

     @Id 
     @SequenceGenerator(name="MOD_PM_ID_GENERATOR", sequenceName="MOD_PM_SEQ", allocationSize=1) 
     @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="MOD_PM_ID_GENERATOR") 
     @Column(name="ID") 
     private long id; 

     @Column(name="COMMIT_NUMBER") 
     private int commitNumber; 


     @Lob() 
     @Basic(fetch=FetchType.LAZY) 
     @Column(name="LIST_ARCHIVE") 
     private byte[] listArchive; 

    .... 

     @Lob 
     @Basic(fetch=FetchType.LAZY) 
     @Column(name="TEXT_MASTER") 
     private String textMaster; 

.... 

@ManyToMany 
    @JoinTable(
     name="MOD_PM_DEPENDENCE" 
     , joinColumns={ 
      @JoinColumn(name="PRIMARY_PM_ID") 
      } 
     , inverseJoinColumns={ 
      @JoinColumn(name="DEPENDENT_PM_ID") 
      } 
     ) 
    private List<ModPm> modPms2; 

和NamedQuery

@NamedQueries({ 
    @NamedQuery(name = ModPm.Q_GET_DEPENDENT_LIST_FOR_NEW_SCOPE, 
      query = "SELECT DISTINCT p FROM ModPm p " + 
        "WHERE p.modSystem.id=(SELECT s.modSystem.id FROM ModScopeType s WHERE s.id=?1) " + 
        "AND p.test=false AND p.rejected=false " + 
        "AND p.modPms2 IS NOT EMPTY"), 

... 
} 

當我試圖執行查詢,遞歸冬眠裝載所有數據庫。來自ModPm類的startinf(包括所有的blob和集合)。

我的persistence.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
    <persistence version="2.0" 
     xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
     <persistence-unit name="mod-db-jpa" transaction-type="JTA"> 
      <provider>org.hibernate.ejb.HibernatePersistence</provider> 
      <jta-data-source>jdbc/security</jta-data-source> 
.... 
      <class>com.ecleasing.db.jpa.entity.ModPm</class> 
.... 
      <exclude-unlisted-classes>true</exclude-unlisted-classes> 
      <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> 
      <validation-mode>CALLBACK</validation-mode> 
      <properties> 
       <property name="hibernate.transaction.manager_lookup_class" 
         value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" /> 
       <property name="hibernate.transaction.factory_class" 
         value="org.hibernate.transaction.CMTTransactionFactory" /> 
       <property name="hibernate.transaction.jta.platform" 
         value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" /> 

       <property name="hibernate.dialect" value="com.ecleasing.db.hibernate.dialect.Oracle10gExtendedDialect" /> 
       <property name="hibernate.format_sql" value="true" /> 

       <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" /> 
       <property name="hibernate.cache.use_second_level_cache" value="true" /> 
       <property name="hibernate.cache.use_query_cache" value="false" /> 

       <property name="hibernate.max_fetch_depth" value="0" /> 

      </properties> 
     </persistence-unit> 
    </persistence> 

我也嘗試着寫有「取= FetchType.LAZY」標註到每個集合,但它並沒有幫助。

+0

延遲加載的基本屬性需要構建時字節碼儀器。你做完了嗎? – 2013-03-10 08:20:25

+0

不,我想。我正在使用maven來構建項目。我加入到persistence.xml中 \t \t \t <屬性名= 「hibernate.bytecode.use_reflection_optimizer」 值= 「真」/> \t \t \t <屬性名= 「hibernate.bytecode.provider」 值= 「Javassist進行」/>但沒有幫助。 – Andrey 2013-03-10 08:38:53

+1

這不是編譯時間字節碼檢測。請參閱http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#performance-fetching-lazyproperties以使用ant任務。 – 2013-03-10 08:41:35

回答

0

THX到JB Nizet,

加入Maven的任務的pom.xml

<plugins> 
      <plugin> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.3</version> 
       <executions> 
        <execution> 
         <id>Hibernate bytecode optimization</id> 
         <phase>process-classes</phase> 
         <configuration> 
          <tasks> 
           <taskdef name="instrument" classname="org.hibernate.tool.instrument.javassist.InstrumentTask"> 
            <classpath> 
             <path refid="maven.dependency.classpath" /> 
             <path refid="maven.plugin.classpath" /> 
            </classpath> 
           </taskdef> 
           <instrument verbose="true"> 
            <fileset dir="${project.build.outputDirectory}"> 
             <include name="**/*.class" /> 
             <exclude name="**/I*_.class,**/WebPageObject.class" /> 
            </fileset> 
           </instrument> 
          </tasks> 
         </configuration> 

         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
+0

它說org.hibernate.tool.instrument.javassist.InstrumentTask不支持「verbose」屬性 – dvelopp 2017-07-25 09:27:36