2

I was about to start writing a program in Java which includes hibernate.

I am confused which should I choose between Annotations and XML Configuration.

I personally like XML configuration because I have been using this technique for sometime.

But I had one doubt: Is annotation faster than XML configuration in the scale of time taken to execute the program?

I personally think that if I use XML, then JVM would have to parse the file and then validate it as well. This would take some time. While, in case of annotations, the container will directly start performing the operations using the JARs available.

Can someone provide me with a clearer understanding on this.

Thanks in advance.

AnirbanDebnath
  • 990
  • 16
  • 26
  • 1
    possible duplicate of : http://stackoverflow.com/questions/182393/xml-configuration-versus-annotation-based-configuration?rq=1 – bruno_cw Nov 17 '15 at 11:46
  • I have read that thread. But here I am asking about speed and performance. The thread you mentioned does not. – AnirbanDebnath Nov 17 '15 at 11:51
  • 2
    oh ok , nevermind then, back to the question at hand, I don't think speed factors too much in this choice, since the time to load up the configurations will be taken only at start up – bruno_cw Nov 17 '15 at 11:53
  • 1
    Most people find annotations simpler to work with since you can directly see what you're doing rather than having to look in xml and code in parallel. Classpath scanning does take a bit since you have to scan through lots of possibly unrelated class files, xml scanning should be a bit faster since there is only a predefined set of xml file locations. But it will won't be more then a (few) seconds of startup time in difference. – zapl Nov 17 '15 at 12:02
  • 1
    Hibernate's annotation scanning doesn't necessitate classpath scanning. That being said, the time required to read annotations and/or read in XML is going to be negligible compared the time it takes Hibernate to generate proxies and other work that it does at startup. So the difference in performance between the two is likely to be tiny (my guess would be less than 5%) compared to the overall startup time. Hibernate does not startup quickly, there isn't much workaround. – Pace Nov 17 '15 at 13:12
  • I guess annotations are picked up/loaded at runtime; as and when the particular class is loaded by jvm. – AnirbanDebnath Nov 18 '15 at 04:22

0 Answers0