2013-11-10 1 views
1

처음에는 USERS 또는 USER라는 이름의 테이블을 만들려고했지만 Google은 MySQL의 예약어이며 QWERTY로 시도했지만 테이블은 만들어지지 않았습니다.최대 절전 모드로 MySQL 테이블을 생성 할 때의 문제

엔티티 클래스

import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 
import javax.persistence.Table; 

@Entity 
@Table(name="QWERTY") 
public abstract class User { 
    @Id 
    @GeneratedValue 
    protected Long id; 
    protected String username; 
    protected String firstname; 
    protected String secondname; 
    protected String middlename; 
    protected String password; 

    @Type(type = "org.hibernate.type.NumericBooleanType") 
    protected Boolean accountIsNotLocked; 

    public User(){ 
    } 

    // getters and setters... 
} 

만들기 테이블

import org.hibernate.cfg.AnnotationConfiguration; 
import org.hibernate.tool.hbm2ddl.SchemaExport; 

import by.grsu.epam.domain.User; 

public class TestUser { 

    public static void main(String[] args) { 
     AnnotationConfiguration config = new AnnotationConfiguration(); 
     config.addAnnotatedClass(User.class); 
     config.configure(); 

     new SchemaExport(config).create(true, true); 
    } 

} 

콘솔 출력

INFO : org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {4.0.2.Final} 
INFO : org.hibernate.Version - HHH000412: Hibernate Core {4.2.7.Final} 
INFO : org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found 
INFO : org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist 
INFO : org.hibernate.cfg.Configuration - HHH000043: Configuring from resource: /hibernate.cfg.xml 
INFO : org.hibernate.cfg.Configuration - HHH000040: Configuration resource: /hibernate.cfg.xml 
INFO : org.hibernate.cfg.Configuration - HHH000041: Configured SessionFactory: null 
INFO : org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect 
INFO : org.hibernate.tool.hbm2ddl.SchemaExport - HHH000227: Running hbm2ddl schema export 
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000402: Using Hibernate built-in connection pool (not for production use!) 
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 2 
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000006: Autocommit mode: false 
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/MySQL] 
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000046: Connection properties: {user=root, password=****} 

    drop table QWERTY if exists 
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: drop table QWERTY if exists 
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if exists' at line 1 

    create table QWERTY (
     id bigint generated by default as identity (start with 1), 
     accountIsNotLocked integer, 
     firstname varchar(255), 
     middlename varchar(255), 
     password varchar(255), 
     secondname varchar(255), 
     username varchar(255), 
     primary key (id) 
    ) 
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table QWERTY (id bigint generated by default as identity (start with 1), accountIsNotLocked integer, firstname varchar(255), middlename varchar(255), password varchar(255), secondname varchar(255), username varchar(255), primary key (id)) 
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'generated by default as identity (start with 1), 
     accountIsNotLocked inte' at line 2 
INFO : org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/MySQL] 
INFO : org.hibernate.tool.hbm2ddl.SchemaExport - HHH000230: Schema export complete 

답변

3

다음과 같이 주석이 accountIsNotLocked. 올바른 방언을 설정해야합니다 : org.hibernate.dialect.MySqlDialect. 그러면 Hibernate는 MySQL에 대한 올바른 문장을 생성 할 것이다.

+0

SpringBoot에 문제가있을 때까지 시간을 절약 한 사람! – sunleo

0

MySQL의 나던 노나가 tive boolean 데이터 유형 - tinyint (1)이 부울 값으로 사용됩니다. 로깅이 올바른 방언 (Using dialect: org.hibernate.dialect.HSQLDialect)를 설정하지 않는 것을 알 수

@Type(type = "org.hibernate.type.NumericBooleanType") 
protected boolean accountIsNotLocked; 
+0

아직도 작동하지 않습니다. –

+0

이전과 동일한 오류가 있습니까? – Sanj

+0

문제의 엔티티 클래스 및 콘솔 출력을 편집했습니다. –

관련 문제