2017-01-29 1 views
1

첫 번째 : 나는 어리석은 실수를 저지르고있을 것입니다..HsqlException : 사용자가 권한이 없거나 객체를 찾을 수 없습니다.

저는 Spring XML에서 Javaconfig로 이전 프로젝트를 변환하려고합니다. 데이터베이스는 메모리상의 HSQLDB 데이터베이스입니다. 불행하게도, 그것은 나에게 오류를주고 내 PersistenceConfig.java 내 SQL 스크립트는 다음

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement 
(stacktrace) 
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: PUBLIC.T_AUTHORITY 
(stacktrace) 
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: PUBLIC.T_AUTHORITY 

있습니다

@Configuration 
@EnableTransactionManagement 
@EnableJpaRepositories(basePackages = "org.jason.application.repository.jpa", 
     entityManagerFactoryRef = "entityManagerFactoryBean") 
public class ApplicationPersistenceConfig { 

    @Bean 
    public JpaTransactionManager transactionManager(EntityManagerFactory emf) { 

     JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(); 
     jpaTransactionManager.setEntityManagerFactory(emf); 
     return jpaTransactionManager; 
    } 

    @Bean 
    public LocalContainerEntityManagerFactoryBean getEntityManagerFactoryBean(DataSource dataSource) { 

     LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean(); 

     entityManagerFactory.setPersistenceUnitName("default"); 
     entityManagerFactory.setDataSource(dataSource); 
     entityManagerFactory.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); 
     entityManagerFactory.setJpaDialect(new HibernateJpaDialect()); 
     entityManagerFactory.setPackagesToScan("org.jason.application.repository.model"); 

     entityManagerFactory.setJpaPropertyMap(hibernateJpaProperties()); 

     return entityManagerFactory; 
    } 

    @Bean 
    public DataSource getDataSource() { 

     BasicDataSource dataSource = new BasicDataSource(); 
     dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); 
     dataSource.setUrl("jdbc:hsqldb:mem:testdb"); 
     dataSource.setUsername("sa"); 
     dataSource.setPassword(""); 
     return dataSource; 
    } 

    private Map<String, ?> hibernateJpaProperties() { 

     HashMap<String, String> properties = new HashMap<>(); 
     properties.put("hibernate.hbm2ddl.import_files", "insert-data.sql"); 
     properties.put("hibernate.hbm2ddl.auto", "create-drop"); 
     properties.put("hibernate.show_sql", "false"); 
     properties.put("hibernate.format_sql", "false"); 
     properties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy"); 
     properties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); 
     properties.put("hibernate.c3p0.min_size", "2"); 
     properties.put("hibernate.c3p0.max_size", "5"); 
     properties.put("hibernate.c3p0.timeout", "300"); // 5mins 

     return properties; 
    } 
} 

CREATE TABLE PUBLIC.T_USER (
    USERID INTEGER NOT NULL PRIMARY KEY, 
     USERNAME VARCHAR_IGNORECASE(50) NOT NULL, 
     PASSWORD VARCHAR_IGNORECASE(50) NOT NULL, 
     ENABLED BOOLEAN NOT NULL, 
    CREATE UNIQUE INDEX IX_USERNAME ON T_USER(USERNAME); 

    CREATE TABLE PUBLIC.T_AUTHORITY (
    AUTHORITYID INTEGER NOT NULL PRIMARY KEY, 
    USERID INTEGER NOT NULL, 
--  USERNAME VARCHAR_IGNORECASE(50) NOT NULL, 
     AUTHORITY VARCHAR_IGNORECASE(50) NOT NULL, 
     CONSTRAINT FK_AUTHORITIES_USERS FOREIGN KEY(USERID) REFERENCES USERS(USERID)); 
     CREATE UNIQUE INDEX IX_AUTH_USERNAME ON T_AUTHORITY (USERID,AUTHORITY); 

INSERT INTO T_USER(USERNAME, PASSWORD, ENABLED) VALUES (1, 'jason','password', true); 
INSERT INTO T_AUTHORITY(AUTHORITYID, USERID, AUTHORITY) VALUES (1, 1, "ROLE_ADMIN"); 

사람이 내가 만든 바보 어떤 실수 볼 수 있을까요?

제이슨

답변

0

나는 생각했던 것처럼 바보 같은 실수였습니다.

다음이 최대 절전 모드 속성은 서로 호환되지 않습니다 :

properties.put("hibernate.hbm2ddl.import_files", "insert-data.sql"); 
    properties.put("hibernate.hbm2ddl.auto", "create-drop"); 

모두 스키마를 만드는 효과가 있습니다.

관련 문제