Hibernate needs you to map all your Entity classes in Hibernate.cfg.xml, but I don’t want to list all of them. I just want to reference the package in which they are all contained. I’ve read that Spring allows your application to autodiscover all your annotated classes with a bean for AnnotationSessionFactoryBean, but I don’t understand how and where I’m supposed to configure this. I do NOT have a persistence.xml file anywhere in my application ==> I’m using Hibernate (Session instead of EntityManager, etc).
Hibernate needs you to map all your Entity classes in Hibernate.cfg.xml, but I don’t
Share
First of all clarify whether you’re using JPA or Hibernate directly.
If you don’t have any persistence.xml it might be that you’re not using JPA (I would recommend using it though, you’ll still be using Hibernate underneath, but your code will be more standard and independent of Hibernate).
Spring does support auto scanning of entity classes through:
I know it works for JPA, not sure for Hibernate directly.
My working spring application config file snippet looks like this, which includes the Hibernate properties (thus eliminating the need of the file completely):