Does it work to put Java XML and persistance annotations on the same bean?
annotations, java, persistence, spring
Solution
Annotations are just meta data. On their own, they don't do anything to your code. You need to use reflection to make use of them. So, yes, you could put any number of annotations on your classes and fields.
Your persistence framework will read the persistence annotations while your XML parser will read the XML annotations.
Eg.
@Entity // JPA
@XmlRootElement(name = "book") // JAXB
@SuppressWarnings(value = "random") // whatever other annotation
public class User {
@Id
@GeneratedValue
@GenericGenerator(name = "incremental", strategy = "increment")
@XmlElement
private Long userID;
// more
}
Problem
I haven't worked an implementation yet but I'm wondering if it's okay to put XML annotations as well as persistance annotations onto the same bean. The reason I'm asking is because I want to read in some XML using Spring OXM, have the XML written to domain objects which are also the domain objects that are mapped to the database (that mapping was already done).