Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hibernate-orm: hbm-xml: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@7d024b28' as the property is read only #22801

Closed
digsb opened this issue Jan 11, 2022 · 7 comments · Fixed by #22814
Assignees
Labels
area/hibernate-orm Hibernate ORM area/jaxb area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Milestone

Comments

@digsb
Copy link
Contributor

digsb commented Jan 11, 2022

Describe the bug

If we have any filter-def tag as part of hbm.xml than we get below exception while building project.

java.lang.RuntimeException: Failed to record call to method public io.quarkus.arc.runtime.BeanContainerListener io.quarkus.hibernate.orm.runtime.HibernateOrmRecorder.initMetadata(java.util.List,org.hibernate.boot.archive.scan.spi.Scanner,java.util.Collection,io.quarkus.hibernate.orm.runtime.proxies.PreGeneratedProxies)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.writeBytecode(BytecodeRecorderImpl.java:509)
	at io.quarkus.deployment.steps.MainClassBuildStep.writeRecordedBytecode(MainClassBuildStep.java:436)
	at io.quarkus.deployment.steps.MainClassBuildStep.build(MainClassBuildStep.java:168)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:829)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.lang.RuntimeException: Failed to substitute io.quarkus.hibernate.orm.runtime.boot.QuarkusPersistenceUnitDefinition@79b350e1
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:672)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1096)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:938)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.writeBytecode(BytecodeRecorderImpl.java:504)
	... 13 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@7d024b28' as the property is read only
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1393)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:938)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:652)
	... 18 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@7d024b28' as the property is read only
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1393)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:938)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1096)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:938)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1356)
	... 21 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@7d024b28' as the property is read only
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1312)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:938)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1356)
	... 27 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@7d024b28' as the property is read only
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1312)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:938)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1232)
	... 30 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@7d024b28' as the property is read only
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1312)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstanceImpl(BytecodeRecorderImpl.java:938)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadObjectInstance(BytecodeRecorderImpl.java:610)
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1232)
	... 33 more
Caused by: java.lang.RuntimeException: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@7d024b28' as the property is read only
	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1303)
	... 36 more

Expected behavior

Project should build successfully.

Actual behavior

Getting Exception.

How to Reproduce?

Steps to Reproduce:

  1. Copy following contents in extensions/hibernate-orm/deployment/src/test/resources/META-INF/hbm-component.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="io.quarkus.hibernate.orm.xml.hbm.NonAnnotatedComponentUsingEntity">
        <id name="id">
            <generator class="identity"/>
        </id>
        <property name="groupId" type="long">
            <column name="GroupId" not-null="true" default="0"/>
        </property>
        <property name="authId" column="AuthId" />
        <component name="value" class="io.quarkus.hibernate.orm.xml.hbm.NonAnnotatedComponent" lazy="false">
            <property name="name">
                <column name="thename"/>
            </property>
        </component>
        <filter name="filter-name" condition="AuthId in (select gm.MemberId from group_members where groupId in (:groupIds)"/>
    </class>
    <filter-def name="filter-name" condition="AuthId in (select gm.MemberId from group_members where groupId in (:groupIds)">
        <filter-param name="groupIds" type="long"/>
    </filter-def>
</hibernate-mapping>
  1. Run Test: HbmXmlComponentTest

Output of uname -a or ver

Linux ubuntu 4.15.0-159-generic #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.18.04) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.18.04, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.6.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)

Additional information

No response

@digsb digsb added the kind/bug Something isn't working label Jan 11, 2022
@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/jaxb area/persistence OBSOLETE, DO NOT USE labels Jan 11, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 11, 2022

/cc @Sanne, @gsmet, @yrodiere

@yrodiere yrodiere self-assigned this Jan 11, 2022
@yrodiere
Copy link
Member

This looks caused by an incomplete JAXB mapping in Hibernate ORM, resulting in the use of JAXBElement where we should use a custom domain type (i.e. JaxbHbmFilterParameterType).

We'll have to fix this upstream.

@yrodiere
Copy link
Member

I decided to work around the problem in Quarkus in the end. See #22814.

@digsb
Copy link
Contributor Author

digsb commented Jan 11, 2022

@yrodiere thanks for quick turn around.

A Query might not be related to this.
Does Quarkus currently support tags <query /> and <sql-query /> in hbm.xml?
Because when we use hbm xml mapping file with 'only' this tags , SessionFactory Inject Fails as Build time with UnsatisfiedResolutionException

[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.hibernate.SessionFactory and qualifiers [@Default]

But if I add one more hbm.xml to the config which has an entity <class /> definition, the build fails again with

[ERROR] Caused by: java.lang.RuntimeException: Cannot serialise field 'scope' on object 'javax.xml.bind.JAXBElement@9320a9a' as the property is read only
[ERROR] 	at io.quarkus.deployment.recording.BytecodeRecorderImpl.loadComplexObject(BytecodeRecorderImpl.java:1303)
[ERROR] 	... 36 more

@yrodiere
Copy link
Member

yrodiere commented Jan 12, 2022

@yrodiere thanks for quick turn around.

Thank you for reporting this!

Because when we use hbm xml mapping file with 'only' this tags , SessionFactory Inject Fails as Build time with UnsatisfiedResolutionException

Unless there's additional mapping (e.g. annotations) you didn't mention, if you use a file with only <query /> and <sql-query /> tags, you don't define any persisted entity, so the Hibernate ORM extension will automatically disable itself because it cannot do anything. You will get a warning in the logs, something like "Hibernate ORM is disabled because no JPA entities were found".

So in that case, it's perfectly normal that you cannot inject a SessionFactory.

But if I add one more hbm.xml to the config which has an entity <class /> definition, the build fails again with

The "Cannot serialise field 'scope'" error has the same cause as this issue and should also be fixed by #22814.

@quarkus-bot quarkus-bot bot added this to the 2.7 - main milestone Jan 12, 2022
@digsb
Copy link
Contributor Author

digsb commented Jan 12, 2022

@yrodiere , it seems logical to enable Hibernate only if there any Entities available.

I tried the fix out and it has resolved all issues related to JAXBElement. I was try to build the project with large subset of entities that we have around 2K+ entities and it failed with exception

[ERROR] 	[error]: Build step io.quarkus.deployment.steps.MainClassBuildStep#build threw an exception: org.objectweb.asm.ClassTooLargeException: Class too large: io/quarkus/deployment/steps/HibernateOrmProcessor$build1373687952

Is there a workaround for this?
I can raise another bug for this if required.

@yrodiere
Copy link
Member

I can raise another bug for this if required.

Please do: this is unlikely to be related to Hibernate ORM itself.

@gsmet gsmet modified the milestones: 2.7 - main, 2.6.3.Final Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/jaxb area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants