Does it work to put Java XML and annotations on persistence on the same bean?

I have not worked on an implementation yet, but I am wondering if it is possible to place XML annotations, as well as annotations on the same bean.

The reason I ask is because I want to read in XML format using Spring OXM, have XML written to domain objects, which are also domain objects that are mapped to the database (this mapping has already been done) ,

+4
source share
1 answer

Annotations are just metadata. By themselves, they do nothing with your code. You must use reflection to use them. So yes, you could add any number of annotations to your classes and fields.

Your persistence structure will read persistence annotations, while your XML parser will read 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 } 
+8
source

All Articles