I have a JPA entity class with jpa annotations but without jaxb annotations:
@Entity
public class Category extends EntityObject {
@Id
private long id;
// getter setter and stuff
}
Everything for jaxb is configured in an external xml file (because we need different serializations of the object).
<xml-bindings package-name="mystuff.category">
<java-types>
<java-type name="mystuff.Category" xml-accessor-type="NONE">
<xml-root-element name="category" />
<java-attributes>
<xml-attribute name="name" java-attribute="name" />
<xml-element name="id2" java-attribute="id" />
</java-attributes>
</java-type>
// morestuff ...
my problems start when i marhall a category instance to xml. The result shows an additional id element that was not configured in the xml. and since category (or entityObject) doesn’t have jaxb annotations i don’t understand where it comes from.
<category xsi:type="category" name="Category_3">
<id>1073741951</id>
<id2>1073741951</id2>
</category>
when i explicitly add an xml-element entry for id to the moxy-xml i get an element that contains the id two times:
<id>10737419511073741951</id>
can somebody tell me how to get rid of this tag and were it comes from?
EDIT
Here the id related code in the EntityObject-Class
@MappedSuperclass
public abstract class EntityObject implements Serializable {
private static final long serialVersionUID = 1L;
public abstract long getId();
@Field // a solr annotation
public void setId(long id) {
if (getId() <= 0) {
setID(id);
}
}
protected abstract void setID(long id);
The problem is due to the
idproperty onEntityObjectbeing overridden on the child objectCategory.Solution #1 –
EntityObjectandCategoryare in the same packageAssuming that
EntityObjectis in the same package asCategoryyou could do the following:Solution #2 –
EntityObjectandCategoryare in different packagesIf
EnityObjectandCategoryare in different packages you can create a second external mapping document:Below is some sample code for bootstrapping from multiple external mapping documents:
Below is the output from running the demo code: