Reputation: 9095
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 folder src/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?
Upvotes: 2
Views: 22876
Reputation: 116281
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.
Upvotes: 8