强制删除JPA数据库

时间:2014-11-18 16:32:41

标签: spring hibernate jpa

我正在使用Spring MVC服务器,我需要删除数据库。

我在application.properties上使用此配置:

spring.datasource.url=jdbc:h2:~/test;AUTO_SERVER=TRUE
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.show-sql: true
spring.jpa.hibernate.ddl-auto=create-drop

我确保在应用程序的注释中输入它:

@PropertySource("application.properties")

但是表格没有被删除,只是它们正常​​加载:

2014-11-18 13:30:28.231  INFO 7472 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2014-11-18 13:30:28.250  INFO 7472 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2014-11-18 13:30:28.306  INFO 7472 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.1.Final}
2014-11-18 13:30:28.307  INFO 7472 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2014-11-18 13:30:28.308  INFO 7472 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2014-11-18 13:30:28.471  INFO 7472 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
2014-11-18 13:30:32.894  INFO 7472 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2014-11-18 13:30:33.010  INFO 7472 --- [           main] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2014-11-18 13:30:33.280  INFO 7472 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000228: Running hbm2ddl schema update
2014-11-18 13:30:33.280  INFO 7472 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000102: Fetching database metadata
2014-11-18 13:30:33.281  INFO 7472 --- [           main] org.hibernate.tool.hbm2ddl.SchemaUpdate  : HHH000396: Updating schema
2014-11-18 13:30:33.289  INFO 7472 --- [           main] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000261: Table found: TEST.PUBLIC.CLIENTE
2014-11-18 13:30:33.289  INFO 7472 --- [           main] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000037: Columns: [creation_date, id, complete_name, logginname, loggin_name]
2014-11-18 13:30:33.289  INFO 7472 --- [           main] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000108: Foreign keys: []
2014-11-18 13:30:33.289  INFO 7472 --- [           main] o.hibernate.tool.hbm2ddl.TableMetadata   : HHH000126: Indexes: [primary_key_9]
     

等...

我需要强行删除数据库。

1 个答案:

答案 0 :(得分:1)

您应该尝试按this question设置spring.jpa.hibernate.hbm2ddl.auto=create-drop

另请注意,由于https://jira.spring.io/browse/SPR-6836,您需要将generateDdl设置为false