Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 261
jnj Avatar asked Jun 02 '26 18:06

jnj


1 Answers

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

like image 107
bdoughan Avatar answered Jun 04 '26 12:06

bdoughan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!