Org.hibernate.cfg.Configuration add packages that host annotated classes

I create the database tables with the following code:

public void createSchema() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.connection.driver_class", driverClassName);
    configuration.setProperty("hibernate.connection.url", url);
    configuration.setProperty("hibernate.connection.username", username);
    configuration.setProperty("hibernate.connection.password", password);
    configuration.setProperty("hibernate.dialect", hibernateDialect);

    configuration.addAnnotatedClass(Base.class);
    configuration.addAnnotatedClass(User.class);
    logger.info("begin database schema creation =========================");
    new SchemaUpdate(configuration).execute(true, true);
    logger.info("end database schema creation ===========================");
}

Here I have indicated the names of annotated classes by the method configuration.addAnnotatedClass. If I have 50 classes, then it will be really dirty.

Can I specify package names for scanning for annotated classes?

+3
source share
2 answers

Hibernate 4, Hibernate 3. Spring Hibernate, , , , Spring.

+3

Reflections , @Entity, . Chech fir   Hibernate 4

+3

All Articles