Search code examples
javahibernateannotationshibernate-mapping

Mapping all the classes in hibernate.cfg.xml with just one line?


I'm a bit lazy and i'm trying to find a single liner to map all my classes in my hibernate.cfg.config. (I'm using annotations not an xml file)

What i've tried to do :

<mapping class="my_group.my_artifact.*"></mapping>

Can this be acheived using one line of code? I've looked to other answers on SO but didn't find a lazy way that fits me, and I'm new to SO to I'll appreciate any helpful comment.


Solution

  • You can't do it using Hibernate only.

    You can use Spring with org.springframework.orm.hibernate5.LocalSessionFactoryBean (package hibernate5 for Hibernate 5, change it if need) or additional libraries as described here:

    Hibernate config not list all Entities in XML