JAXB and how to work around duplicate variables

For our current adf project we’re generating webservice proxy clients against the wsdls of our OSB services.
In one of the services we had the next xsd construction :

[sourcecode language=”xml”]



XML Represenation of the Employee domain object
















[/sourcecode]

The object contains both an id-element and an id-attribute.
When trying to generate the Webservice proxy against the wsdl containing this definition, JDeveloper will generate the next error :
Error creating model from wsdl “file:/EmployeeService.wsdl”: The following location is relevant to the above errorProperty “Id” is already defined. Use to resolve this conflict.
JAXB tries to generate the java representation of this schema and will (try to) generate a java class in which it will generate 2 variables with the name of ‘id’.

The wizard also comes with the solution on how we could implement the fix for this.
Change the schema to :

[sourcecode language=”xml”]
xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb” jaxb:version=”2.0″>


XML Represenation of the Employee domain object

















[/sourcecode]

We added a few things.

  • add xmlns:jaxb=”http://java.sun.com/xml/ns/jaxb” jaxb:version=”2.0 to the schema-tag
  • add the xs:appinfo-element (and childs) to the “xs:element name=”id” element

or make use of an external binding file
[sourcecode language=”xml”]





[/sourcecode]

With this property we can force jaxb to generate a variable idElement instead of the id-element. So no duplicates on variable-name will get generated.
This will result in the next java code fragment :
[sourcecode language=”xml”]
public class EmployeeType {

@XmlElement(name = “id”)
protected BigInteger idElement;
protected String firstname;
protected String lastname;
protected XMLGregorianCalendar birthdate;
@XmlAttribute
protected BigInteger id;
[/sourcecode]

No duplicates in variables, since it generated idElement and id.

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

2 Responses to “JAXB and how to work around duplicate variables”

commenter

It would be helpful if you could say how to use the external binding in netbeans

commenter

It’s been a while back since i wrote this blog and currently i don’t use Netbeans.
But are these blogs any help for you :
http://netbeans.org/kb/docs/websvc/jaxb.html
http://wiki.netbeans.org/NB6JAXBSample1

I guess you can add the binding file by use of the new file wizard in Netbeans. After that you could copy/paste the content of for example the blog in it.

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>