【发布时间】:2018-05-28 17:00:06
【问题描述】:
我使用下面的链接作为参考来实现从 PostgreSQL 数据库中延迟加载图像: 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
在控制台中,我收到消息:
“由于未启用任何功能,因此跳过 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。
【问题讨论】:
-
你是说使用maven构建应用时,增强步骤没有执行?
-
我是说当我从数据库中获取用户对象时加载了头像。
-
如何验证是否执行了增强步骤?
-
当我从命令行运行 maven build 时,我通常会看到增强插件的输出。你不是吗?如果没有,也许插件没有被 maven 执行?
-
我明确地运行目标:org.hibernate.orm.tooling:hibernate-enhance-maven-plugin:5.3.1.Final:enhance.In Console 我可以看到消息:“[WARNING] Skipping Hibernate字节码增强插件执行,因为没有启用任何功能”。
标签: java postgresql hibernate