簡體   English   中英

字節碼增強無法正常工作

[英]Bytecode enhancement not working

我使用以下鏈接作為參考,以實現從PostgreSQL DB延遲加載圖像: URL

在我的用戶實體中,我聲明了字節數組字段:

@Lob
@Basic(fetch = FetchType.LAZY)
private byte[] avatar;

在pom.xml文件中,我包含了hiberante增強插件:

<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
    <execution>
        <configuration>
            <failOnError>true</failOnError>
            <enableLazyInitialization>true</enableLazyInitialization>
        </configuration>
        <goals>
            <goal>enhance</goal>
        </goals>
    </execution>
</executions>

問題是,當我從數據庫中獲取用戶實體時,頭像字節數組也被加載了,這是我不想要的。

我了解到hibernate-enhance-maven-plugin應該可以增強/更改User.class文件,但這沒有發生。

我在這里想念什么嗎?

更新:

我執行增強目標:
org.hibernate.orm.tooling:hibernate-enhance-maven-plugin:enhance
在consol我收到消息:
“由於未啟用任何功能,因此跳過了Hibernate字節碼增強插件的執行”
我檢查了插件jar文件hibernate-enhance-maven-plugin-5.3.1.Final.jar,我看到下面的代碼:

@Mojo(name="enhance", defaultPhase=LifecyclePhase.COMPILE, 
requiresDependencyResolution=ResolutionScope.COMPILE_PLUS_RUNTIME)
public class MavenEnhancePlugin
extends AbstractMojo
{
private List<File> sourceSet = new ArrayList();
@Component
private BuildContext buildContext;
@Parameter(property="base", defaultValue="${project.build.outputDirectory}")
private String base;
@Parameter(property="dir", defaultValue="${project.build.outputDirectory}")
private String dir;
@Parameter(property="failOnError", defaultValue="true")
private boolean failOnError = true;
@Parameter(property="enableLazyInitialization", defaultValue="false")
private boolean enableLazyInitialization;
@Parameter(property="enableDirtyTracking", defaultValue="false")
private boolean enableDirtyTracking;
@Parameter(property="enableAssociationManagement", defaultValue="false")
private boolean enableAssociationManagement;
@Parameter(property="enableExtendedEnhancement", defaultValue="false")
private boolean enableExtendedEnhancement;

private boolean shouldApply()
{
    return (this.enableLazyInitialization) || (this.enableDirtyTracking) || 
    (this.enableAssociationManagement) || (this.enableExtendedEnhancement);
}

public void execute()
throws MojoExecutionException, MojoFailureException
{
if (!shouldApply())
{
  getLog().warn("Skipping Hibernate bytecode enhancement plugin execution since no feature is enabled");
  return;
}
.
.
.
}

看起來shouldApply()方法返回false,不知道為什么,因為我將pom文件中的properties(enableLazyInitialization)設置為true。

如果您不打算使用該插件來參與構建生命周期的某些階段,則不應使用執行。 在pom.xml中嘗試以下配置:

        <plugin>
            <groupId>org.hibernate.orm.tooling</groupId>
            <artifactId>hibernate-enhance-maven-plugin</artifactId>
            <version>5.2.13.Final</version>
            <configuration>
                <failOnError>true</failOnError>
                <enableLazyInitialization>true</enableLazyInitialization>
                <enableDirtyTracking>false</enableDirtyTracking>
                <enableAssociationManagement>false</enableAssociationManagement>
            </configuration>
            <goals>
                <goal>enhance</goal>
            </goals>
        </plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM