spring-boot is not creating hsqldb database
You'd be better using Spring Boot to manage your configuration. It will pass Hibernate configuration to Hibernate while also auto-creating your DataSource and database for you.
I would move all of your configuration into src/main/resources/application.properties
:
# DataSource
spring.datasource.url=jdbc:hsqldb:file:/home/kleber/.webapp/testedb
spring.datasource.username=sa
# Hibernate
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create
I've removed some unnecessary configuration. For example, the configuration of driverClassName
as Spring Boot will infer it from the url and the empty DataSource password as that's the default. You can see some documentation of the configuration properties and their default values here.
Kleber Mota
Updated on June 22, 2020Comments
-
Kleber Mota almost 4 years
In my current spring project, I start to use spring-boot with spring-jpa to create and manage a HSQLDb database.
I have this
hibernate.properties
in thee foldersrc/main/resources
from my project:# jdbc.X jdbc.driverClassName=org.hsqldb.jdbc.JDBCDriver jdbc.url=jdbc:hsqldb:file:/home/kleber/.webapp/testedb jdbc.user=sa jdbc.pass= # hibernate.X hibernate.dialect=org.hibernate.dialect.HSQLDialect hibernate.show_sql=false hibernate.hbm2ddl.auto=create
my pom.xml have this dependencies:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> </dependencies>
my main class is that:
@Controller @EnableJpaRepositories @EnableAutoConfiguration public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } @RequestMapping(value = "/signin") public String signin(Model model) { return "acesso/signin"; } @RequestMapping(value = "/admin") public String admin(Model model) { return "private/admin"; } @RequestMapping(value = "/") public String index(Model model) { return "public/index"; } }
when I run the application, I can see this in the console:
2014-10-30 17:58:51.708 INFO 31413 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.6.Final} 2014-10-30 17:58:51.713 INFO 31413 --- [ main] org.hibernate.cfg.Environment : HHH000205: Loaded properties from resource hibernate.properties: {jdbc.url=jdbc:hsqldb:file:/home/kleber/.webapp/testedb, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.show_sql=false, jdbc.user=sa, hibernate.bytecode.use_reflection_optimizer=false, hibernate.hbm2ddl.auto=create, jdbc.driverClassName=org.hsqldb.jdbc.JDBCDriver, jdbc.pass=} 2014-10-30 17:58:51.714 INFO 31413 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist 2014-10-30 17:58:52.089 INFO 31413 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 2014-10-30 17:58:52.191 INFO 31413 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect 2014-10-30 17:58:52.385 INFO 31413 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory 2014-10-30 17:58:52.838 INFO 31413 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export 2014-10-30 17:58:52.845 INFO 31413 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
but no database is created in the path defined by the property
jdbc.url
.ANyone can tell me what I am doing wrong?
-
Kleber Mota over 9 yearsWhy application.properties? When I run the application, the spring-boot looks for a file named hibernate.properties. Also, does really matters if I use all the options or no? my problem it's the database is not being created with this configuration (it's working when I manually configure it with a HibernateConfig class).
-
Andy Wilkinson over 9 yearsSpring Boot doesn't look for hibernate.properties, Hibernate does. You can see that from the log output you've included in the question. Putting the configuration in application.properties allows Spring Boot to configure things for you, reducing the amount of configuration that you have to do yourself. If you're not interested in having things configured automatically with sensible defaults and, instead, you prefer to configure everything manually, then you're missing out on one of the major reasons for using Spring Boot.
-
Hatem Jaber over 8 yearsThis thread is a little old, but still relevant. I added the url and username properties in order to get Spring to generate a file database and it still uses the in-memory. It creates the testdb... but it's not using it.
-
Hassan Faghihi over 7 yearswhat is home is that linux based URL or root of executable?