我使用下面的链接作为参考来实现从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:冬眠 - 增强 - Maven的插件:提高
在consol我收到消息:
&#34;跳过Hibernate字节码增强插件执行,因为没有启用任何功能&#34;
我检查了插件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文件中的属性(enableLazyInitialization)设置为true。
答案 0 :(得分:0)
如果您不打算使用该插件来参与构建生命周期的某些阶段,则不应使用执行。在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>