i have an Spring + Hibernate based application where the most properties are setted using annotations.
My AppConfig class looks like:
//package declarations and imports
@EnableWebMvc
@Configuration
@ComponentScan({ "com.package.subpackage.*" })
@Import({ SecurityConfig.class })
public class AppConfig {
@Bean(name = "dataSource")
public DriverManagerDataSource dataSource() {
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setDriverClassName("com.mysql.jdbc.Driver");
driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/fur");
Properties prop = new Properties();
prop.setProperty("hibernate.hbm2ddl.auto", "create");
driverManagerDataSource.setConnectionProperties(prop);
driverManagerDataSource.setUsername("root");
driverManagerDataSource.setPassword("");
return driverManagerDataSource;
}
//other methods...
}
The problem I have is that the tables associated with my Java classes are not auto-created in my database.
I dont add examples of my class beacause I think its in the configuration the issue, but please let me know if is needed.
You are setting the properties containing
hibernate.hmb2ddl.autoon the data source, which doesn't know anything about ORM layer such as Hibernate. You should pass these properties toLocalSessionFactoryBuilderbean or such.You could use similar configuration to set-up Hibernate with the required properties: