I'm trying to configure Spring and Hibernate without xml. Here's my SessionFactory bean. When I add annotated class to configuration - it works properly. I want to do it automatically, but adding a package to configuration doesnt helps for some reason, I get "Identificator is not mapped" error
@Bean
public SessionFactory sessionFactory(){
Properties hibernateProperties = new Properties();
hibernateProperties.put("hibernate.connection.driver_class",ds_driver);
hibernateProperties.put("hibernate.connection.url",ds_url);
hibernateProperties.put("hibernate.connection.username",ds_username);
hibernateProperties.put("hibernate.connection.password",ds_password);
hibernateProperties.put("hibernate.show_sql", false);
hibernateProperties.put("connection.pool_size", 1);
hibernateProperties.put("current_session_context_class", "thread");
hibernateProperties.put("hibernate.hbm2ddl.auto", "update");
org.hibernate.cfg.Configuration configuration = new org.hibernate.cfg.Configuration();
configuration.addPackage("app.entity"); // **doesnt work**
configuration.addAnnotatedClass(Identificator.class); // **works fine**
configuration.addProperties(hibernateProperties);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}