Pela capacidade do meu micro troquei o banco Mysql pelo HSQLDB 2.4.0, atualizei o pom.xml trocando o banco:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.0</version>
</dependency>
também atualizei a classe, JpaConfigurator
@Bean
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:hsql://localhost/projeto_jpa");
dataSource.setUsername("SA");
dataSource.setPassword("");
return dataSource;
}
@Bean //propriedades do persistense.xml
public LocalContainerEntityManagerFactoryBean getEntityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPackagesToScan("br.com.caelum");
entityManagerFactory.setDataSource(dataSource);
entityManagerFactory
.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties props = new Properties();
props.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
props.setProperty("hibernate.show_sql", "true");
props.setProperty("hibernate.cache.use_second_level_cache", "true");
props.setProperty("hibernate.hbm2ddl.auto", "update"); //create-drop
props.setProperty("hibernate.generate_statistics", "true");
entityManagerFactory.setJpaProperties(props);
return entityManagerFactory;
}
Porém ocorre erro ao inicar o projeto, no Tomcat v8.5:
INFORMAÇÕES: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Hibernate: insert into Loja (id, nome) values (default, ?)
Hibernate: insert into Loja (id, nome) values (default, ?)
Hibernate: insert into Categoria (id, nome) values (default, ?)
Hibernate: insert into Categoria (id, nome) values (default, ?)
Hibernate: insert into Produto (id, descricao, linkDaFoto, loja_id, nome, preco) values (default, ?, ?, ?, ?, ?)
abr 18, 2018 2:34:00 PM org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'criadorDeProdutos': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
...
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
...
... 23 more
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
...
... 40 more
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: PRODUTO in statement [insert into Produto (id, descricao, linkDaFoto, loja_id, nome, preco) values (default, ?, ?, ?, ?, ?)]
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
...
abr 18, 2018 2:34:00 PM org.apache.catalina.core.StandardContext startInternal
GRAVE: One or more listeners failed to start. Full details will be found in the appropriate container log file
abr 18, 2018 2:34:00 PM org.apache.catalina.core.StandardContext startInternal
GRAVE: Context [/projeto-jpa-2] startup failed due to previous errors
abr 18, 2018 2:34:00 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: Closing Spring root WebApplicationContext
abr 18, 2018 2:34:00 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
ADVERTÊNCIA: The web application [projeto-jpa-2] registered the JDBC driver [org.hsqldb.jdbc.JDBCDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Podem ajudar com a configuração?