字节码增强不起作用



我使用以下链接作为参考来实现从PostgreSQL DB延迟加载图像: 网址

在我的用户实体中,我声明了字节数组字段:

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

问题是当我从数据库中获取用户实体时,还会加载头像字节数组,这是我不想要的。

我知道休眠增强插件应该增强/更改用户.class文件,这没有发生。

我在这里错过了什么吗?

更新:

我执行增强目标:org.hibernate.orm.tooling:hibernate-enhance-maven-plugin:
enhance
在 consol 中,我收到消息:">
跳过休眠字节码增强插件执行,因为没有启用任何功能"
我检查了插件 jar 文件休眠-增强-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 文件中将属性(启用懒惰初始化(设置为 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>

最新更新