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).
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With