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

Getting UnmarshalException #20

Closed
heruan opened this issue Mar 12, 2018 · 6 comments
Closed

Getting UnmarshalException #20

heruan opened this issue Mar 12, 2018 · 6 comments

Comments

@heruan
Copy link

heruan commented Mar 12, 2018

When I try to generate the schema, I get:

Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.hibernate.org/xsd/orm/hbm", local:"hibernate-mapping"). Expected elements are <{}hibernate-mapping>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent (UnmarshallingContext.java:741)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError (Loader.java:262)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError (Loader.java:257)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement (Loader.java:124)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement (UnmarshallingContext.java:1149)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement (UnmarshallingContext.java:574)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement (UnmarshallingContext.java:556)
    at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement (InterningXmlVisitor.java:75)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXEventConnector.handleStartElement (StAXEventConnector.java:261)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge (StAXEventConnector.java:130)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0 (UnmarshallerImpl.java:460)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal (UnmarshallerImpl.java:435)
    at org.hibernate.boot.jaxb.internal.AbstractBinder.jaxb (AbstractBinder.java:171)
    at org.hibernate.boot.jaxb.internal.MappingBinder.doBind (MappingBinder.java:61)
    at org.hibernate.boot.jaxb.internal.AbstractBinder.doBind (AbstractBinder.java:102)
    at org.hibernate.boot.jaxb.internal.AbstractBinder.bind (AbstractBinder.java:57)
    at org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl$1.addDocument (AdditionalJaxbMappingProducerImpl.java:92)
    at org.hibernate.envers.configuration.internal.EntitiesConfigurator.configure (EntitiesConfigurator.java:111)
    at org.hibernate.envers.boot.internal.EnversServiceImpl.doInitialize (EnversServiceImpl.java:154)
    at org.hibernate.envers.boot.internal.EnversServiceImpl.initialize (EnversServiceImpl.java:118)
    at org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl.produceAdditionalMappings (AdditionalJaxbMappingProducerImpl.java:99)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:288)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build (MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build (MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build (MetadataBuilderImpl.java:87)
    at org.hibernate.boot.MetadataSources.buildMetadata (MetadataSources.java:179)
    at de.jpdigital.maven.plugins.hibernate5ddl.DdlGeneratorHibernate52.generateDdl (DdlGeneratorHibernate52.java:95)
    at de.jpdigital.maven.plugins.hibernate5ddl.DdlGeneratorHibernate52.generateDdl (DdlGeneratorHibernate52.java:132)
    at de.jpdigital.maven.plugins.hibernate5ddl.GenerateDdlMojo.execute (GenerateDdlMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:564)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

but I do not have XML files with that namespace anywhere. Did anyone ever get into this problem?

@jpdigital
Copy link
Owner

No real idea what is happening here. Does the project contain any XML mapping files for Hibernate? Also, it would be helpful if you can provide an example project with the error. That would be helpful do investigate this error.

@heruan
Copy link
Author

heruan commented Mar 13, 2018

I don't have any XML files, just annotations. But debugging I see Envers creates mapping files on the fly (in memory maybe) and then parses them. Worth noting I'm on Java 9 which needs to have an explicit dependency on java.xml.bind, but all works running the app normally and fails only with the plugin. Maybe Hibernate tricks the parsing process somehow?

@heruan
Copy link
Author

heruan commented Mar 20, 2018

I've tested the plugin and it works if run with Java 1.8, but it fails with Java 9 throwing that exception. You can test this with just a simple entity annotated with @Audited and run the plugin with Java 9 (adding some additional dependencies [1]).

I've also recreated a bare-bone plugin to replicate the issue: https://github.com/heruan/hibernate-ddl-generator but unfortunately I didn't find a solution yet.

So currently this plugin does not work with Java 9 if there are Envers entities, maybe you wish to add a note for this in the README.

[1] Dependencies needed for the plugin to run with Java 9:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>javax.activation-api</artifactId>
    <version>1.2.0</version>
</dependency>

@jwgmeligmeyling
Copy link
Contributor

jwgmeligmeyling commented Aug 7, 2018

What if you add

<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

To your hbm file? Not sure if http://www.hibernate.org/xsd/orm/hbm is a valid DTD uri.

Edit I am aware that the hbm file in question is generated by envers. Perhaps we can try to see if we can reproduce the issue for various DTDs?

@jwgmeligmeyling
Copy link
Contributor

jwgmeligmeyling commented Aug 7, 2018

Also, the 5.2 plugin is dependent on Hibernate 5.2.10, any post 5.2.10 fixes for Java 9+ support will not be available unless you specify the exact Hibernate artifact as plugin dependency.

(you may have to override hibernate-entitymanager as the plugin is dependent on that and not hibernate-core).

@heruan
Copy link
Author

heruan commented Aug 29, 2018

Thanks to HHH-12893 and highsource/jaxb-tools#120 seems the issue is related to the Maven plugin runtime in Java 9 and 10 not binding XML schema.

Preloading the bindings as done by maven-jaxb2-plugin works around this:

void setupBindInfoPackage() {
    String nsuri = "http://www.hibernate.org/xsd/orm/hbm";
    String packageInfoClassName = "org.hibernate.boot.jaxb.hbm.spi.package-info";
    try {
        final Class<?> packageInfoClass = Class
                .forName(packageInfoClassName);
        final XmlSchema xmlSchema = packageInfoClass
                .getAnnotation(XmlSchema.class);
        if (xmlSchema == null) {
            this.getLog().warn(MessageFormat.format(
                    "Class [{0}] is missing the [{1}] annotation. Processing bindings will probably fail.",
                    packageInfoClassName, XmlSchema.class.getName()));
        } else {
            final String namespace = xmlSchema.namespace();
            if (nsuri.equals(namespace)) {
                this.getLog().warn(MessageFormat.format(
                        "Namespace of the [{0}] annotation does not match [{1}]. Processing bindings will probably fail.",
                        XmlSchema.class.getName(), nsuri));
            }
        }
    } catch (ClassNotFoundException cnfex) {
        this.getLog().warn(MessageFormat.format(
                "Class [{0}] could not be found. Processing bindings will probably fail.",
                packageInfoClassName), cnfex);
    }
}

@heruan heruan closed this as completed Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants