eclipse-ee4j / jaxb-ri

Jaxb RI
https://eclipse-ee4j.github.io/jaxb-ri/
BSD 3-Clause "New" or "Revised" License
202 stars 110 forks source link

xjc generates duplicated 'create' methods in ObjectFactory when using episode file #1729

Open patric-r opened 1 year ago

patric-r commented 1 year ago

Hi there,

We have a rather complex set of schema files. The schema files can be grouped into 2 parts, one generic part A and one specific part B which reuses types from A.

As always, we use xjc to generate jaxb classes for part A and let xjc generate an episode file. When generating the jaxb classes for part B we used that episode file in order to avoid duplicate class creation which works perfectly.

However, when looking into the ObjectFactory of part B, it suprisingly contains create methods for classes of part A and those create methods are already part of the ObjectFactory of part A.

As a result, when marshalling our JAXB tree, it fails with:

java.util.concurrent.CompletionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
The element name {http://namespace/of/part/A has more than one mapping.
    this problem is related to the following location:
at public javax.xml.bind.JAXBElement com.part.B.xml.ObjectFactory.createProblematicType(com.part.A.xml.ProblematicType)

When manually removing those redudant create methods from part B's ObjectFactory, everything works as expected.

Question: Why does xjc create those duplicate create() methods?

(Note: jaxb 2.3.5 has been used)

laurentschoelens commented 1 year ago

Hi @patric-r

Could you test with latest jaxb 2.3.8 release and say if this solve your issue ?

What tool do you use to generate java files from schema ?

Thanks for your responses