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”]
[/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
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”]
[/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.
2 Responses to “JAXB and how to work around duplicate variables”
It would be helpful if you could say how to use the external binding in netbeans
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.