Hibernate : mapping files or annotations?

后端 未结 2 1515
旧巷少年郎
旧巷少年郎 2021-02-04 15:06

As I started working with Hibernate a few days ago, I was just wondering : suppose you\'re starting a project from scratch. Would you use annotation-based mapping or Hibernate m

2条回答
  •  一个人的身影
    2021-02-04 16:12

    What advantages I see in using @Annotations:

    • compiler-safe
    • based on @Entity you can easily distinguish entity from no-entity
    • with packagesToScan Spring's feature entites are easily scannable
    • moving entites from packages to packages or class renaming is easy

    What advantages I see in using XML:

    • it does not litters java classes with unnecessary vendor-specific annotations (imagine java model class with JPA, JAXB, SOLRJ annotations)
    • configuration in one place
    • easier to maintain as a whole

    We use annotations, but keep XML as an option.

提交回复
热议问题