Annotating Map caused compile error w/bytecode enhancement


#1

I am trying to annotate a java map like this (Contact.java)::

    @IgnoreSizeOf
@OneToMany(orphanRemoval = true, cascade = {CascadeType.ALL}, mappedBy = "contact")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@MapKey(name = "documentID")
private Map<Long, ContactAttachment> attachments = new HashMap<Long, ContactAttachment>();

With the one to many side like this (ContactAttachment.java)::

@IgnoreSizeOf
@ManyToOne
@JoinColumn(name = "ContactID", nullable = true)
private Contact contact;

@Column(name = "DocumentID", nullable = true)
private Long documentId;

I am getting this compile time error from my btyecode enhancer (using the gradle orm plugin) … Caused by: compile error: contains(com.icims.contact.ContactAttachment) not found in java.util.Map . I am not sure what is wrong, as I followed this guide and I am 99% sure I followed it correctly. https://vladmihalcea.com/jpa-hibernate-synchronize-bidirectional-entity-associations/

Previously, it worked with this hbm.xml mapping (Contact.hbm.xml)

[<]map name="attachments" inverse="true" cascade="all,delete-orphan"[>]
[<]cache usage="read-write"/>
[<]key column="ContactID"/>
[<]map-key type="long" column="DocumentID" />
[<]one-to-many entity-name="ContactAttachment" />
[<]/map>

(ContactAttachment.hbm.xml)

	[<]many-to-one name="contact" entity-name="Contact" fetch="select" column="ContactID" not-null="true" cascade="none"/>
	[<]property name="documentId" type="long" column="DocumentID" not-null="true"/>

Any help would be appreciated, thanks.


#2

Can you try to come up with a self contained test case?

We have a template here: https://github.com/hibernate/hibernate-test-case-templates/tree/master/orm/hibernate-orm-5 . I don’t think using Gradle or Maven should have any consequence.


#3

Will work on that, and I’ll comment back here when im done and link the PR. Also, if this helps, I saw this in the stacktrace as well.

“Caused by: org.hibernate.bytecode.enhance.spi.EnhancementException: Could not enhance entity class [com.icims.contact.Contact] to add field writer method [$$_hibernate_write_attachments]
at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.generateFieldWriter(PersistentAttributesEnhancer.java:305)
at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.enhancePersistentAttribute(PersistentAttributesEnhancer.java:136)”


#4

Which version are you using? I suspect not 5.3 as we moved to ByteBuddy by default instead of Javassist.

Try to come up with a self contained test case using our template but setting the version to the ORM version you use. Then we’ll be able to see if the issue is already fixed or if it’s still there.

By the way, further in the EnhancementException stacktrace, you probably have a wrapped exception: this is the useful one that might help understanding the first issue.


#5

We are using hibernate version 5.2 … still working on that Test Case. Havent had much time in the office yet but should finish up the test case soon. Here is the whole stacktrace.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:Web:compileJava’.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:98)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:68)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$RunTasksAction.execute(DefaultGradleLauncher.java:230)
    at org.gradle.initialization.DefaultGradleLauncher$RunTasksAction.execute(DefaultGradleLauncher.java:227)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:161)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:112)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:95)
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:66)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:31)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    Caused by: org.gradle.api.GradleException: Unable to enhance class : D:\sourcecode\irecruiter\Web\build\classes\main\com\icims\contact\Contact.class
    at org.hibernate.orm.tooling.gradle.HibernatePlugin.doEnhancement(HibernatePlugin.java:181)
    at org.hibernate.orm.tooling.gradle.HibernatePlugin.access$300(HibernatePlugin.java:46)
    at org.hibernate.orm.tooling.gradle.HibernatePlugin$2.execute(HibernatePlugin.java:131)
    at org.hibernate.orm.tooling.gradle.HibernatePlugin$2.execute(HibernatePlugin.java:80)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:692)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:675)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:115)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:109)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:90)
    … 70 more
    Caused by: org.hibernate.bytecode.enhance.spi.EnhancementException: Unable to enhance persistent attribute [com.icims.contact.Contact:attachments]
    at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.enhancePersistentAttribute(PersistentAttributesEnhancer.java:145)
    at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.enhance(PersistentAttributesEnhancer.java:63)
    at org.hibernate.bytecode.enhance.internal.javassist.EntityEnhancer.enhance(EntityEnhancer.java:66)
    at org.hibernate.bytecode.enhance.internal.javassist.EnhancerImpl.enhance(EnhancerImpl.java:136)
    at org.hibernate.bytecode.enhance.internal.javassist.EnhancerImpl.enhance(EnhancerImpl.java:72)
    at org.hibernate.orm.tooling.gradle.HibernatePlugin.doEnhancement(HibernatePlugin.java:178)
    … 82 more
    Caused by: org.hibernate.bytecode.enhance.spi.EnhancementException: Could not enhance entity class [com.icims.contact.Contact] to add field writer method [$$_hibernate_write_attachments]
    at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.generateFieldWriter(PersistentAttributesEnhancer.java:305)
    at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.enhancePersistentAttribute(PersistentAttributesEnhancer.java:136)
    … 87 more
    Caused by: javassist.CannotCompileException: [source error] contains(com.icims.contact.ContactAttachment) not found in java.util.Map
    at javassist.CtBehavior.insertBefore(CtBehavior.java:774)
    at javassist.CtBehavior.insertBefore(CtBehavior.java:734)
    at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.handleBiDirectionalAssociation(PersistentAttributesEnhancer.java:400)
    at org.hibernate.bytecode.enhance.internal.javassist.PersistentAttributesEnhancer.generateFieldWriter(PersistentAttributesEnhancer.java:288)
    … 88 more
    Caused by: compile error: contains(com.icims.contact.ContactAttachment) not found in java.util.Map
    at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:749)
    at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:695)
    at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:157)
    at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.TypeChecker.booleanExpr(TypeChecker.java:523)
    at javassist.compiler.TypeChecker.atExpr(TypeChecker.java:592)
    at javassist.compiler.ast.Expr.accept(Expr.java:68)
    at javassist.compiler.TypeChecker.booleanExpr(TypeChecker.java:527)
    at javassist.compiler.TypeChecker.atBinExpr(TypeChecker.java:337)
    at javassist.compiler.ast.BinExpr.accept(BinExpr.java:41)
    at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
    at javassist.compiler.CodeGen.compileBooleanExpr(CodeGen.java:236)
    at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:384)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:355)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atForStmnt(CodeGen.java:497)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:359)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:398)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:355)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.Javac.compileStmnt(Javac.java:567)
    at javassist.CtBehavior.insertBefore(CtBehavior.java:754)
    … 91 more

BUILD FAILED

Total time: 2 mins 0.759 secs


#6

It looks like a possible bug. Once you have the test case in place, open a Jira issue and attach the test case to it. Thanks.