Java Hibernate中@Formula的延迟加载不起作用

Java Hibernate中@Formula的延迟加载不起作用,java,hibernate,maven,ant,lazy-loading,Java,Hibernate,Maven,Ant,Lazy Loading,我试图使我的一个字段可计算,但我真的不想在检索实体时一直计算它。我想要的是,仅在当前查询或仅在调用getter时需要它的情况下计算它。这就是我使用@Formula的原因: @Basic(fetch = FetchType.LAZY) @Formula("(SELECT max(myEntity.CREATION_TIME) FROM MyEntity myEntity WHERE myEntity.account_id = id)") private LocalDateTime entitie

我试图使我的一个字段可计算,但我真的不想在检索实体时一直计算它。我想要的是,仅在当前查询或仅在调用getter时需要它的情况下计算它。这就是我使用@Formula的原因:

@Basic(fetch = FetchType.LAZY)
@Formula("(SELECT max(myEntity.CREATION_TIME) FROM MyEntity myEntity 
WHERE myEntity.account_id = id)")
private LocalDateTime entitiesModifiedDate;
为了使其工作,我使用字节码工具,如下所示:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <id>Instrument domain classes</id>
                    <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="**/entity/*.class" />
                                </fileset>
                            </instrument>
                        </tasks>
                    </configuration>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

使用hibernate增强maven插件,或者尝试使用maven antrun插件的最新版本1.8

 <plugins>
    <plugin>
        <groupId>org.hibernate.orm.tooling</groupId>
        <artifactId>hibernate-enhance-maven-plugin</artifactId>
        <executions>
            <execution>
                <phase>process-classes</phase>
                <goals>
                    <goal>enhance</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

参考资料:

hibernate enhance maven插件已编译,但没有任何更改。子查询仍然是主查询的一部分。附加到问题。我希望这个部分不会出现,因为它是延迟加载。从MyEntity MyEntity中选择MAXevent.creation\u time,其中MyEntity.accountId=account1\u.id作为公式0\u更新到1.8版本也没有帮助。您可以通过git共享此项目部分吗?
 <plugins>
    <plugin>
        <groupId>org.hibernate.orm.tooling</groupId>
        <artifactId>hibernate-enhance-maven-plugin</artifactId>
        <executions>
            <execution>
                <phase>process-classes</phase>
                <goals>
                    <goal>enhance</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>