2016-12-09 15 views
1

私は数日前にSpringと作業を始めました。何らかの理由でHibernateにテーブルエンティティを自動的に作成させることができません(私は他のプロジェクトでHibernateを数回使用しました。この能力を有する)。これをどうやって解決するのですか?私は役に立つかもしれないいくつかのコードを添付しています。Spring 4 + Hibernate 4インテグレーション。テーブルが自動的に作成されない

HibernateConfiguration.class

@Configuration 
@EnableTransactionManagement 
@ComponentScan("br.com.jeffersontpadua.spring.config") 
@PropertySource(value = {"classpath:application.properties"}) 
public class HibernateConfiguration { 
    @Autowired 
    private Environment environment; 

    @Bean 
    public LocalSessionFactoryBean sessionFactory() { 
     LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); 

     sessionFactory.setDataSource(dataSource()); 
     sessionFactory.setPackagesToScan("br.com.jeffersontpadua.spring.model"); 
     sessionFactory.setHibernateProperties(hibernateProperties()); 

     return sessionFactory; 
    } 

    @Bean 
    public DriverManagerDataSource dataSource() { 
     DriverManagerDataSource dataSource = new DriverManagerDataSource(); 

     dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName")); 
     dataSource.setUrl(environment.getRequiredProperty("jdbc.url")); 
     dataSource.setUsername(environment.getRequiredProperty("jdbc.username")); 
     dataSource.setPassword(environment.getRequiredProperty("jdbc.password")); 

     return dataSource; 
    } 

    private Properties hibernateProperties() { 
     Properties properties = new Properties(); 

     properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect")); 
     properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql")); 
     properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql")); 
     properties.put("hibernate.hbm2dll.auto", environment.getRequiredProperty("hibernate.hbm2dll.auto")); 

     System.out.println("Hibernate config: " + environment.getRequiredProperty("hibernate.hbm2dll.auto")); 

     return properties; 
    } 

    @Bean 
    @Autowired 
    public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) { 
     HibernateTransactionManager transactionManager = new HibernateTransactionManager(); 

     transactionManager.setSessionFactory(sessionFactory); 

     return transactionManager; 
    } 
} 

application.properties

jdbc.driverClassName = com.mysql.jdbc.Driver 
jdbc.url = jdbc:mysql://localhost:3306/coaching_works 
jdbc.username = root 
jdbc.password = 1234 
hibernate.dialect = org.hibernate.dialect.MySQLDialect 
hibernate.format_sql = true 
hibernate.show_sql = true 
hibernate.hbm2dll.auto = update 

Costumer.java

@Entity 
@Table(name = "costumer") 
public class Costumer { 
    @Id 
    @GeneratedValue 
    @Column(name = "id", nullable = false, updatable = false, unique = true) 
    private int id; 

    @Column(name = "full_name", nullable = false, length = 160) 
    private String fullName; 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public String getFullName() { 
     return fullName; 
    } 

    public void setFullName(String fullName) { 
     this.fullName = fullName; 
    } 
} 

答えて

2

あなたはタイプミスがあります:プロパティが..ddl(hibernate.hbm2ddl.autoと呼ばれます。..ない..dll ..)

+0

それは問題だとは思えません。ご助力ありがとうございます。心から感謝する。 o / –

関連する問題