4

I am using HSQLDB with Spring Boot and Hibernate 5.0.11 Final. When I run it on embedded Tomcat 8.5, Hibernate starts to alter the tables which are not created and gives error:

user lacks privilege or object not found

Why it happen?

File application.properties

spring.datasource.hikari.jdbc-url=jdbc:hsqldb:mem:test
spring.datasource.hikari.username=sa
spring.datasource.hikari.password=
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true

Console:

INFO  main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.11.Final}
    INFO  main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
    INFO  main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
    INFO  main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    INFO  main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
    INFO  main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
    Hibernate: alter table blog drop constraint FKpxk2jtysqn41oop7lvxcp6dqq
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table blog drop constraint 
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : user lacks privilege or object not found: PUBLIC.BLOG
    Hibernate: alter table item drop constraint FK60ndn1v2u4j38nfc5yahfkb7e
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table item drop constraint 
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : user lacks privilege or object not found: PUBLIC.ITEM
    Hibernate: alter table user_roles drop constraint FKj9553ass9uctjrmh0gkqsmv0d
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table user_roles drop constraint 
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : user lacks privilege or object not found: PUBLIC.USER_ROLES
    Hibernate: alter table user_roles drop constraint FK7ecyobaa59vxkxckg6t355l86
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table user_roles drop constraint 
    ERROR  main] org.hibernate.tool.hbm2ddl.SchemaExport  : user lacks privilege or object not found: PUBLIC.USER_ROLES


    Hibernate: drop table blog if exists
    Hibernate: drop table item if exists
    Hibernate: drop table role if exists
    Hibernate: drop table user if exists
    Hibernate: drop table user_roles if exists
    Hibernate: create table blog 
    Hibernate: create table item 
    Hibernate: create table role 
    Hibernate: create table user 
    Hibernate: create table user_roles    

ConfigForJPA

@Configuration
@EnableAutoConfiguration
@EntityScan(basePackages = {"io.boot.spring.entities"})
@EnableJpaRepositories(basePackages = {"io.boot.spring.repositories"})
@EnableTransactionManagement
public class ConfigForJPA {
    @Bean
    public LocalContainerEntityManagerFactoryBean EntityManagerFactory(
            EntityManagerFactoryBuilder builder) {
        return builder
                .dataSource(dataSource())
                .packages("io.boot.spring")
                .persistenceUnit("io.boot.springs.entities")
                .build();
    }

console

j.LocalContainerEntityManagerFactoryBean : 
Initialized JPA EntityManagerFactory for persistence unit 'io.boot.springs.entities'

o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: -5501, SQLState: 42501

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'initDBService':
Invocation of init method failed;
nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException:
could not prepare statement; SQL [call next value for hibernate_sequence];
nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement

@Service public class InitDBService {

@Autowired
private RoleRepository roleRepository;

@PostConstruct
public void init(){
    Role roleUser = new Role();
    roleUser.setName("ROLE_USER");
    roleRepository.save(roleUser);

@Entity public class Role {

@Id
@GeneratedValue
private Integer id;
private String name;


console:

Hibernate: insert into Role (id, name) values (default, ?)
SQL Error: -5501, SQLState: 42501
user lacks privilege or object not found: ROLE
Error creating bean with name 'initDBService': 
Invocation of init method failed; 
nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException:
could not prepare statement; SQL [insert into Role (id, name)
elk
  • 153
  • 1
  • 5
  • 14
  • 1
    Throughout the 5.x release line we've made some improvements to the schema tooling support. Can you confirm that this is still observed on releases 5.2.6 / 5.2.7 ? – Naros Feb 03 '17 at 16:29
  • With 5.2.6 Final I get the following error message : *************************** APPLICATION FAILED TO START *************************** Description: Method mvcConversionService in org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport required a bean named 'entityManagerFactory' that could not be found. Action: Consider defining a bean named 'entityManagerFactory' in your configuration. – elk Feb 03 '17 at 18:24
  • That error is likely due to misconfiguration, see http://stackoverflow.com/a/24531432/1572269 for details. – Naros Feb 03 '17 at 18:36
  • with the above config file I get the same error. .packages("io.boot.spring") refers to the base package and .persistenceUnit("io.boot.springs.entities") refers to the package where I keep the entities is this configuration correct? – elk Feb 05 '17 at 16:31
  • Rename the `@Bean` method for your entity manager as `entityManagerFactory`. You'll notice the first character is lower case. – Naros Feb 05 '17 at 17:24
  • Thank you it was helpful but now I have another problem – elk Feb 05 '17 at 18:52
  • For MySQL, specify `@GeneratedValue(strategy = GenerationType.IDENTITY)` should resolve it. – Naros Feb 05 '17 at 20:16
  • o.k. I added the (strategy = GenerationType.IDENTITY) but it didn't help .I am using hsqlDB – elk Feb 05 '17 at 20:58
  • Sorry my apologies, could have sworn I saw MySQL. It looks like your spring integration is likely using the old generators. Be sure to that `hibernate.id.new_generator_mappings` is set to `true` and that should trigger the `hibernate_sequences` table creation iirc. – Naros Feb 05 '17 at 21:27
  • sorry ,setting hibernate.id.new_generator_mappings to true didn't help I think I will close this discussion and open a new one with new topic. – elk Feb 06 '17 at 16:27

0 Answers0