jnj
jnj

Reputation: 775

JAXBException when marshalling a class with JPA annotations

I got the following exception when marshalling Comment objects to JSON:

javax.xml.bind.JAXBException: class javax.jdo.identity.LongIdentity nor any of its super class is known to this context. at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:594) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:648)

Below is my Comment definition, note that I mixed JAXB annotations (for marshalling) and JPA ones (for persistence with GAE).

@Entity
@XmlRootElement(name = "Comment")
@XmlAccessorType(XmlAccessType.FIELD)
public class Comment {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @XmlElement(name = "CommentId")
    private Long commentId;

    @Basic
    @XmlElement(name = "Author")
    private String author;

...
}

What I don't get is why the exception has something to do with LongIdentity?

Upvotes: 3

Views: 878

Answers (2)

jnj
jnj

Reputation: 775

Blaise really shed light on my question, the problem solved and here is the modified Comment class.

@Entity
@XmlRootElement(name = "Comment")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Comment {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @XmlElement(name = "CommentId")
    public Long getCommentId();

    @Basic
    @XmlElement(name = "Author")
    public String getAuthor();

...
}

Upvotes: 2

bdoughan
bdoughan

Reputation: 149007

Try annotating the properties instead of the fields. The JPA implementation may have used byte code manipulation to add a field of type LongIdentity.

Upvotes: 5

Related Questions