5

Hi my question is not technical. I want to know if hibernate 5 supports XML based entity mapping or not.

My requirement is like below :

I want a backend on Jersey-Hibernate. My front end is Android application. I want to keep my Entity POJOs in a common project such that they will be shared by both app and server. Gson will serialize/deserialize both side. But because android application doesn't support all java library in compilation, I don't want my common(POJO) depending on some library; In this case hibernate annotations. So I am planning to use XML based configuration.

Vlad Mihalcea
  • 123,941
  • 58
  • 509
  • 849
Kuldeep Yadav
  • 1,360
  • 3
  • 20
  • 34

2 Answers2

12

Hibernate 5 supports both the legacy HBM mappings as well as the JPA XML mappings too. However, HBM mappings are no longer the recommended approach to map entities. As illustrated in the new User Guide, all examples make use of annotations.

There are more features provided by Hibernate-specific annotations than it is the case with HBM mappings. In Hibernate 6, it is planned to add an extension mechanism to the JPA XML mappings, therefore HBM mappings are deprecated.

Since you are migrating to Hibernate 5, it's a good idea to migrate from HBM to annotations too.

Vlad Mihalcea
  • 123,941
  • 58
  • 509
  • 849
  • 4
    I want to keep my POJO independent of all dependencies, but if I use annotations then I will have to set dependency on maven Hibernate annotation. Thats why I want hbm. Can you please tell me some other way if there is any? – Kuldeep Yadav Aug 14 '16 at 05:58
  • You can depend only on JPA annotations. Therefore, javax.persistence is the only dependency. But you need it anyway. – Vlad Mihalcea Aug 14 '16 at 08:00
  • But android doesn't comple with JPA annotation library. So hbm.xml is my best option. – Kuldeep Yadav Aug 15 '16 at 16:31
  • Hello Vlad, is the statement still valid that hbm will be deprecated? And are there time schedules when it will be removed? – GreenRover Jan 11 '19 at 10:56
  • Yes, HBM been deprecated for a long time, but there is no timeline for when it will be removed. Anyway, annotations are better supported than HBM, so you are better off migrating anyway. – Vlad Mihalcea Jan 11 '19 at 11:55
1

Yes, according to documentation (where authors recommended using annotations for mapping) is said that xml mapping is still possible: docs

So on - you can still us *.hbm.xml for entity mapping.

EDIT: ofc I mean *.hbm.xml

ByeBye
  • 6,211
  • 5
  • 28
  • 59