users@jaxb.java.net

Re: [HJ3] Cannot attach annotations to 'ref' elements

From: Kostis Anagnostopoulos <ankostis_at_gmail.com>
Date: Fri, 26 Jan 2007 15:45:49 +0200

Hi again Aleksei,

I've made some patches to improve the way the XJC2 plugin dumps
SAXParseExceptions.
As the xjc error-handling was coded, it neglected SAXParseException's
"embedded" exception, although it is this one that holds any errors,
and not its cause!
(Also back-ported these fixes to xjc1 plugin).

Checkout the latest maven-jaxb2-plugin (yours) and build it if you
need to see more descriptive errors (don't forget to use the
-Dmaven.XXX.debug=true param).


Please, read more for the problems i'm having regarding HJ3.

On 1/26/07, Kostis Anagnostopoulos <ankostis_at_gmail.com> wrote:
> Hi Aleksei,
>
> best wishes for this new year,
>
> On 1/25/07, Aleksei Valikov <valikov_at_gmx.net> wrote:
> > Hi.
> >
> > > it may be a jaxb-2.x problem but it still does botther me!
> > >
> > > I have a schema like this:
> > > <xsd:complexType name="portsType">
> > > <xsd:sequence>
> > > <xsd:element ref="proci:problems" minOccurs="0" >
> > > <xsd:annotation>
> > > <xsd:appinfo>
> > > <hj:ignored/>
> > > </xsd:appinfo>
> > > </xsd:annotation>
> > > </xsd:element>
> > > </xsd:sequence>
> > > </xsd:complexType>
> > >
> > > And the XJC complains:
> > >
> > > [ERROR] XJC while parsing schema(s)
> > > file:/home/kana/work/hyperjaxb3-hibernate-sample-0.1/src/main/resources/larysi.xsd[54,26]:
> > >
> > > org.xml.sax.SAXParseException: The prefix "hj" for element
> > > "hj:ignored" is not bound.
> > >
> > >
> > > Any ideas why this happens?
> >
> > Have you configured the hj prefix correctly?
> > Does it work in other places? Like normal elements and so on?
> >
>
> You were right, the customizations do not work anywhere!
> The problem is actually more complex than i had originally thought.
> As soon as the bindings get more complicated (i haven't been able to
> define the crash point yet...), the hj3 plugin first throws a NPE and
> then no customization work, at all.
>
> When i tried to scan through the code for the NPE, i could not locate
> the offending line (probably the plugin has not been in sync with the
> latest sources).
>
> Here is the NPE:
>
> [INFO] Parsing input schema(s)...
> [INFO] Compiling input schema(s)...
> [ERROR] XJC while compiling schema(s): java.lang.NullPointerException
> at org.jvnet.hyperjaxb3.hibernate.plugin.HibernatePlugin.run(HibernatePlugin.java:153)
> at com.sun.tools.xjc.model.Model.generateCode(Model.java:234)
> at org.jvnet.jaxb2.maven2.AbstractXJC2Mojo.runXJC(AbstractXJC2Mojo.java:468)
> at org.jvnet.jaxb2.maven2.AbstractXJC2Mojo.executeImp(AbstractXJC2Mojo.java:131)
> at org.jvnet.hyperjaxb3.maven2.Hyperjaxb3Mojo.execute(Hyperjaxb3Mojo.java:391)
> at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
> at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
> at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
> at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
> at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
> at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
> at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
> at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
> at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
> at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
> at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
> at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
> at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
>
> [ERROR] XJC while compiling schema(s)[33]:
> com.sun.istack.SAXParseException2: compiler was unable to honor this
> hj:ignored customization. It is attached to a wrong place, or its
> inconsistent with other bindings.
> at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:66)
> at com.sun.tools.xjc.model.Model.generateCode(Model.java:246)


Now here is my problem concerning the NPE (look at the embedded ex
down below). It has something to do with many-to-one customization:



[ERROR] XJC while compiling schema(s): java.lang.NullPointerException
        at org.jvnet.hyperjaxb3.hibernate.plugin.HibernatePlugin.run(HibernatePlugin.java:159)
        at com.sun.tools.xjc.model.Model.generateCode(Model.java:234)
        at org.jvnet.jaxb2.maven2.AbstractXJC2Mojo.runXJC(AbstractXJC2Mojo.java:468)
        at org.jvnet.jaxb2.maven2.AbstractXJC2Mojo.executeImp(AbstractXJC2Mojo.java:131)
        at org.jvnet.hyperjaxb3.maven2.Hyperjaxb3Mojo.execute(Hyperjaxb3Mojo.java:391)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Embeded ex:java.lang.NullPointerException
        at org.jvnet.hyperjaxb3.hibernate.customizations.impl.DefaultMappingCreationStrategy.createManyToOne(DefaultMappingCreationStrategy.java:759)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.single.ComplexSingleStrategy.process(ComplexSingleStrategy.java:61)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.single.ComplexSingleStrategy.process(ComplexSingleStrategy.java:17)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.DefaultFieldStrategy.processComplexSingleField(DefaultFieldStrategy.java:163)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.DefaultFieldStrategy.processHomoSingleField(DefaultFieldStrategy.java:43)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.DefaultFieldStrategy.processSingleField(DefaultFieldStrategy.java:30)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.DefaultFieldStrategy.process(DefaultFieldStrategy.java:20)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.DefaultFieldStrategy.process(DefaultFieldStrategy.java:14)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.DefaultFieldsStrategy.process(DefaultFieldsStrategy.java:35)
        at org.jvnet.hyperjaxb3.hibernate.strategy.field.DefaultFieldsStrategy.process(DefaultFieldsStrategy.java:15)
        at org.jvnet.hyperjaxb3.hibernate.strategy.clazz.ClassMappingStrategy.process(ClassMappingStrategy.java:37)
        at org.jvnet.hyperjaxb3.hibernate.strategy.clazz.ClassMappingStrategy.process(ClassMappingStrategy.java:18)
        at org.jvnet.hyperjaxb3.hibernate.strategy.clazz.ClassStrategy.process(ClassStrategy.java:20)
        at org.jvnet.hyperjaxb3.hibernate.strategy.clazz.ClassStrategy.process(ClassStrategy.java:10)
        at org.jvnet.hyperjaxb3.hibernate.strategy.DefaultPrincipalStrategy.process(DefaultPrincipalStrategy.java:310)
        at org.jvnet.hyperjaxb3.hibernate.strategy.DefaultPrincipalStrategy.process(DefaultPrincipalStrategy.java:43)
        at org.jvnet.hyperjaxb3.strategy.impl.DefaultOutlineProcessor.process(DefaultOutlineProcessor.java:31)
        at org.jvnet.hyperjaxb3.hibernate.plugin.HibernatePlugin.generateMappings(HibernatePlugin.java:206)
        at org.jvnet.hyperjaxb3.hibernate.plugin.HibernatePlugin.run(HibernatePlugin.java:140)
        at com.sun.tools.xjc.model.Model.generateCode(Model.java:234)
        at org.jvnet.jaxb2.maven2.AbstractXJC2Mojo.runXJC(AbstractXJC2Mojo.java:468)
        at org.jvnet.jaxb2.maven2.AbstractXJC2Mojo.executeImp(AbstractXJC2Mojo.java:131)
        at org.jvnet.hyperjaxb3.maven2.Hyperjaxb3Mojo.execute(Hyperjaxb3Mojo.java:391)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

[ERROR] XJC while compiling schema(s)[770]:
com.sun.istack.SAXParseException2: compiler was unable to honor this
hj:ignored customization. It is attached to a wrong place, or its
inconsistent with other bindings.
        at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:66)
        at com.sun.tools.xjc.model.Model.generateCode(Model.java:246)
        at org.jvnet.jaxb2.maven2.AbstractXJC2Mojo.runXJC(AbstractXJC2Mojo.java


When i tried to simplify things a bit, i finally got the behavior i
was talking about (ref bindings not working)

---
I've attached 2 archived samples manifesting my problems.
I hope they make it through the mailling list.
  1) hyperjaxb3-ankostis-ref-problem.tgz  (14kb)
  2) hyperjaxb3-ankostis-many-to-one-pronlem.tgz  (17kb)
The first one is a stripped-down version of the second.  The second is
the schemas as i had used them successfully in a HJ2 project, that i
now want to upgrade them to HJ3.   The stack traces included in this
final msg are from building the second sample.
Any help appreciated.
Regards,
  Kostis