Do Domain Classes usually get JPA or JAXB Annotations or both?

前端 未结 5 860
小鲜肉
小鲜肉 2020-12-08 05:28

I have a Java enterprise application that provides a web service, has a domain layer, and a hibernate persistence layer. In this particular case, there is not a huge differ

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 06:23

    I agree that using the same model classes is the right approach. If you are concerned about annotation clutter, you could use a JAXB implementation (such as EclipseLink JAXB) that provides a mechanism for externalizing the metadata:

    • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLink-OXM.XML

    Also since you are using a JPA model EclipseLink JAXB (MOXy) has extensions for making this easier:

    • http://bdoughan.blogspot.com/2010/07/jpa-entities-to-xml-bidirectional.html
    • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA

    Here is an example of using one model with JAXB & JPA to create a RESTful service:

    • Part 1 - The database
    • Part 2 - JPA entities
    • Part 3 - Mapping entities to XML using JAXB
    • Part 4 - The RESTful service
    • Part 5 - The client

提交回复
热议问题