0

我有 ModPm 课

    @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;

和命名查询

@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 类开始(包括所有 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>

我还尝试为每个集合编写带有“fetch=FetchType.LAZY”的注释,但它没有帮助。

4

1 回答 1

0

感谢 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>
于 2013-03-10T16:15:00.197 回答