users@jaxb.java.net

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

From: Kostis Anagnostopoulos <ankostis_at_gmail.com>
Date: Fri, 26 Jan 2007 17:40:38 +0200

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)

Fixed It!

The createManyToOne() method didn't check whether some attribute
exists before invoking its getValue() method.

Aleksei, remember to check it out from the source.

Friendly Regards,
  Kostis