No. You can't say Hibernate to scan packages for persistent classes even with the last Hibernate 5 version.
Using Spring
The common way to use Spring for that, as @Srini suggested.
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>my.com.entities</value>
<value>my.com.other.entities</value>
</list>
</property>
</bean>
Note that depends of Hibernate version you need to use package: org.springframework.orm.hibernate5
, org.springframework.orm.hibernate4
.
Using fluent-hibernate
If you don't want to use Spring, you can use
EntityScanner from fluent-hibernate library (you will not need to have other jars, except the library). Apart this, it has some useful features for Hibernate 5 and Hibernate 4, including entities scanning, a Hibernate 5 implicit naming strategy, a nested transformer and others.
For Hibernate 4 and Hibernate 5:
Configuration configuration = new Configuration();
EntityScanner.scanPackages("my.com.entities", "my.com.other.entities")
.addTo(configuration);
SessionFactory sessionFactory = configuration.buildSessionFactory();
Using a new Hibernate 5 bootstrapping API:
List<Class<?>> classes = EntityScanner
.scanPackages("my.com.entities", "my.com.other.entities").result();
MetadataSources metadataSources = new MetadataSources();
for (Class<?> annotatedClass : classes) {
metadataSources.addAnnotatedClass(annotatedClass);
}
SessionFactory sessionFactory = metadataSources.buildMetadata()
.buildSessionFactory();
Using other libraries
If you already use a library that can be used for scanning, for an example Reflections, there is a test project with examples of using various libraries for entity scanning: hibernate-scanners-test.