I have the following constellation: B1.xsd and B2.xsd both import A.xsd. Using maven-hyperjaxb3-plugin I created Java classes with JPA annotations for both B1.xsd and B2.xsd. So the classes of A.xsd are created in the project of B1.xsd as well es in the project of B2.xsd. In order to use this two sets of classes in one persistence unit, I set through jaxb external binding the database schema on each Entity, like shown in Editing @java.persitence.Table in external jaxb-Binding.
The problem is, after deploying to wildfly, wildfly throws org.hibernate.DuplicateMappingException: duplicate import: B1_ClassName refers to both B1_ClassName and B2_ClassName (try using auto-import=\"false\")"}}
So what I need to do is editing the name parameter of the Entity annotation through jaxb external binding so that
@XmlRootElement(name = "B1_Element1")
@Immutable
@Cacheable(true)
@Entity(name = "B1_Element1")
@Table(name = "B1_Element1")
public class B1_Element1
implements Serializable, Equals, HashCode, ToString
{
...
}
will look like
@XmlRootElement(name = "B1_Element1")
@Immutable
@Cacheable(true)
@Entity(name = "PACKAGE_NAME.B1_Element1")
@Table(name = "B1_Element1")
public class B1_Element1
implements Serializable, Equals, HashCode, ToString
{
...
}
My actual bindings-xjc.xjb looks like this
<jaxb:globalBindings localScoping="toplevel">
<xjc:serializable />
</jaxb:globalBindings>
<jaxb:bindings schemaLocation="B1.xsd"
node="/xs:schema">
<hj:persistence>
<hj:default-generated-id name="Hjid">
<orm:generated-value strategy="IDENTITY" />
</hj:default-generated-id>
<hj:default-entity>
<orm:table schema="B1_database_schema" />
</hj:default-entity>
</hj:persistence>
<jaxb:schemaBindings>
<jaxb:package name="b1.package.name" />
</jaxb:schemaBindings>
</jaxb:bindings>
Anybody has an idea how I can edit the name parameter of @java.persitence.Entity?
Disclaimer: I am the author of Hyperjaxb.
The answer is that you should not need to customize this. I.e. if you need to customize this, something is wrong.
The problem that you're facing is because you generate two sets of classes for your A.xsd
schema, probably in different packages. This can be the case if you're either have chameleon schema (A.xsd
has no target namespace) or if you just compile it twice because you have B1.xsd
and B2.xsd
.
The correct solution is not to compile A.xsd
twice. I hope you don't have chameleon schema (this is a very bad design pattern for JAXB). In this case you can either compile A.xsd
, B1.xsd
and B2.xsd
together or you can compile all of the separately. You can compile A.xsd
first and the use it as an episode in B1 and B2. See Using Episodes on how it works.
In any case you should not produce different packages for A.xsd
classes.
To answer your specific question - try customizing your complex types with:
<hj:entity name="MyUniqueName"/>
I think this should override the automatically generated name. However that's not the way to go.
ps. Here's a test project for episodes:
https://github.com/highsource/hyperjaxb3/tree/master/ejb/tests/episodes