복붙노트

[SPRING] Hibernate는 테이블을 자동으로 생성하지 않는다.

SPRING

Hibernate는 테이블을 자동으로 생성하지 않는다.

나는 Hibernate와 Spring 프레임웍을 가진 Maven 프로젝트를 가지고있다. 하이버 네이트가 자동적으로 테이블을 생성하기를 원하지만, 기존 테이블은 모두 삭제되고 필요한 테이블은 생성되지 않는다. 세션 팩토리 초기화 중에 예외가 발생하지 않지만 Player 엔터티를 저장하려고하면 예외가 throw됩니다.

수동으로 테이블을 만들고 hibernate.hbm2ddl.auto 속성을 "validate"로 변경하면 모든 것이 잘 동작합니다. Hibernate가 테이블을 생성하지 않는 이유는 무엇입니까?

스프링 설정 파일 :

<context:component-scan  base-package="org.meluk.billboard.business.controller" />
<tx:annotation-driven transaction-manager="txManager" />
<bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations" >
        <list>
            <value>/WEB-INF/config/jdbc.properties</value>
        </list>
    </property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${hibernate.connection.driver_class}" />
    <property name="url" value="${hibernate.connection.url}" />
    <property name="username" value="${hibernate.connection.username}" />
    <property name="password" value="${hibernate.connection.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
    <property name="packagesToScan" value="org.meluk.billboard.jpa" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="hibernate.c3p0.min_size">${hibernate.c3p0.min_size}</prop>
            <prop key="hibernate.c3p0.max_size">${hibernate.c3p0.max_size}</prop>
            <prop key="hibernate.c3p0.timeout">${hibernate.c3p0.timeout}</prop>
            <prop key="hibernate.c3p0.max_statements">${hibernate.c3p0.max_statements}</prop>
        </props>
    </property>
</bean>

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

jdbc.properties 파일 :

hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/BillboardDB
hibernate.connection.username=root
hibernate.connection.password=1234
hibernate.default_schema=BillboardDB
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=create
hibernate.show_sql=true
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50

최대 절전 모드 종속성 :

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>${hibernateVersion}</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-c3p0</artifactId>
  <version>${hibernateVersion}</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-tools</artifactId>
  <version>${hibernateToolsVersion}</version>
</dependency>

해결법

  1. ==============================

    1.나는 그 문제를 해결한다. Hibernate는 MysqlInnoDBDialect로 테이블을 생성 할 수 없었다. 이제 대신 MySQL5InnoDBDialect를 사용합니다.

    나는 그 문제를 해결한다. Hibernate는 MysqlInnoDBDialect로 테이블을 생성 할 수 없었다. 이제 대신 MySQL5InnoDBDialect를 사용합니다.

  2. ==============================

    2.다음 항목을 hibernateProperties 소품에 추가하십시오.

    다음 항목을 hibernateProperties 소품에 추가하십시오.

    <prop key="hibernate.hbm2ddl.auto">create</prop>
    
  3. from https://stackoverflow.com/questions/11291940/hibernate-does-not-create-tables-automatically by cc-by-sa and MIT license