Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:50:20+00:00 2026-05-31T15:50:20+00:00

I have a JPA entity class with jpa annotations but without jaxb annotations: @Entity

  • 0

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:50:21+00:00Added an answer on May 31, 2026 at 3:50 pm

    The problem is due to the id property on EntityObject being overridden on the child object Category.

    Solution #1 – EntityObject and Category are in the same package

    Assuming that EntityObject is in the same package as Category you could do the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="mystuff.category">
        <xml-schema namespace="http://www.example.com/customer"
            element-form-default="QUALIFIED" />
        <java-types>
            <java-type name="EntityObject">
                <java-attributes>
                    <xml-transient java-attribute="id" />
                </java-attributes>
            </java-type>
            <java-type name="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>
        </java-types>
    </xml-bindings>
    

    Solution #2 – EntityObject and Category are in different packages

    If EnityObject and Category are in different packages you can create a second external mapping document:

    <?xml version="1.0" encoding="UTF-8"?>
    <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="another.pkg">
        <xml-schema namespace="http://www.example.com/customer"
            element-form-default="QUALIFIED" />
        <java-types>
            <java-type name="EntityObject">
                <java-attributes>
                    <xml-transient java-attribute="id" />
                </java-attributes>
            </java-type>
        </java-types>
    </xml-bindings>
    

    Below is some sample code for bootstrapping from multiple external mapping documents:

    package forum9724475;
    
    import java.util.*;
    import javax.xml.bind.*;    
    import org.eclipse.persistence.jaxb.JAXBContextFactory;
    import another.pkg.EntityObject;
    import mystuff.category.Category;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            Map<String, Object> properties = new HashMap<String, Object>(1);
            List<String> oxm = new ArrayList<String>(2);
            oxm.add("mystuff/category/oxm.xml");
            oxm.add("another/pkg/oxm.xml");
            properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, oxm);
            JAXBContext jc = JAXBContext.newInstance(new Class[] {Category.class}, properties);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    
            Category category = new Category();
            category.setId(1073741951);
            marshaller.marshal(category, System.out);
        }
    
    }
    

    Below is the output from running the demo code:

    <?xml version="1.0" encoding="UTF-8"?>
    <category xmlns="http://www.example.com/customer">
       <id2>1073741951</id2>
    </category>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPA entity similar to; public class Inventory { private String productname;
I have a problem with JPA 1.0 (OpenJPA) Following situation @Entity public class A{
I have the following class (which is a JPA entity listener): @Service public class
Assume we have following JPA Entities: class Parent { @Id private Long id; }
Say I have this class: @Entity @Table(name=PICTURE) public class Picture{ private String category1, category2;
A typical JPA entity looks like: @Entity public class Person { @Id private int
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I have a JPA object which has a many-to-many relationship like this: @Entity public
I have a Formula defined as: @Entity @Table(name = MyEntity) @org.hibernate.annotations.Table(appliesTo = MyEntity) public
A have a JPA entity that has timestamp field and is distinguished by a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.