【问题标题】:.HsqlException: user lacks privilege or object not found.HsqlException:用户缺少权限或找不到对象
【发布时间】:2017-06-14 18:39:12
【问题描述】:

首先:我可能只是犯了一个愚蠢的错误。

我正在将我的一个旧项目从 Spring XML 转换为 Javaconfig。该数据库是内存中的 HSQLDB 数据库。不幸的是,它给了我这个错误:

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

下面是我的 PersistenceConfig.java 和我的 SQL 脚本:

@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");

谁能看到我犯了什么愚蠢的错误?

杰森

【问题讨论】:

    标签: java spring hibernate hsqldb


    【解决方案1】:

    和我想的一样,这是个愚蠢的错误。

    以下两个hibernate属性互不兼容:

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

    两者都有创建架构的效果。

    【讨论】:

      猜你喜欢
      • 2019-09-09
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 2013-03-06
      • 2019-05-31
      • 2017-08-31
      • 1970-01-01
      相关资源
      最近更新 更多