Is there any Utility available to convert XML based config files (say in Spring or Hibernate) to Annotations? If not would it be worthwhile to build such a tool?
Hi,
Go to the following page
https://www.hibernate.org/hib_docs/tools/reference/en/html/ant.html
And see item 4.4.2.
POJO java code exporter (<hbm2java>)
It says:
<hbm2java> is a java codegenerator. Options for controlling wether JDK 5 syntax can be used and whether the POJO should be annotated with EJB3/Hibernate Annotations.
<hibernatetool destdir="${build.dir}/generated">
<configuration configurationfile="hibernate.cfg.xml"/>
<hbm2java jdk5="true" ejb3="true"/>
</hibernatetool>
About ejb3 attribute, it says:
Code will contain EJB 3 features, e.g. using annotations from javax.persistence and org.hibernate.annotations
Hibernate Tools provide this kind of functionality.
They can read existing mappings using either XML files or annotations and subsequently export configuration to XML files or generate annotated POJOs.
Hibernatetool Ant task documentation has examples of how to do both.
That said, my experience with it (DB reverse engineering via older version) has been somewhat mixed; generated POJOs provde a good basis but have to be corrected by hand. This may or may not be the case for hbm-to-annotations translation, though.