栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

模式未放在hbmddl.auto = create.drop上

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

模式未放在hbmddl.auto = create.drop上

该评论实际上是不正确的。从很久以前开始,与“创建”相比,“创建-
删除”的真实行为是前者在关闭SessionFactory时会删除架构。“创建”本身会执行注释中所说的内容,即删除架构并在启动时重新创建。为了进行验证,将“
org.hibernate”日志记录设置为跟踪将显示使用“ create”或“ create-drop”删除该架构,然后在启动时创建该架构:

INFO - Running hbm2ddl schema exportDEBUG - import file not found: /import.sqlINFO - exporting generated schema to databaseTRACE - total checked-out connections: 0TRACE - using pooled JDBC connection, pool size: 0DEBUG - alter table Bar drop constraint FK103F39E150191DEBUG - Unsuccessful: alter table Bar drop constraint FK103F39E150191DEBUG - Table "BAR" not found; SQL statement:alter table Bar drop constraint FK103F39E150191 [42102-149]DEBUG - drop table Bar if existsDEBUG - drop table Foo if existsDEBUG - create table Bar (id integer generated by default as identity, foo_id integer, primary key (id))DEBUG - create table Foo (id integer generated by default as identity, primary key (id))DEBUG - alter table Bar add constraint FK103F39E150191 foreign key (foo_id) references FooINFO - schema export complete

但是,在关闭(SessionFactory.close())时,“创建”会给出

INFO - closingINFO - cleaning up connection pool: jdbc:h2:file:D:/dev/projects/testbed/test-db-for-hibernate-create-drop

而通过“ create-drop”,您会看到

INFO - closingINFO - Running hbm2ddl schema exportDEBUG - import file not found: /import.sqlINFO - exporting generated schema to databaseTRACE - total checked-out connections: 0TRACE - using pooled JDBC connection, pool size: 0DEBUG - alter table Bar drop constraint FK103F39E150191DEBUG - drop table Bar if existsDEBUG - drop table Foo if existsINFO - schema export completeTRACE - returning connection to pool, pool size: 1INFO - cleaning up connection pool: jdbc:h2:file:D:/dev/projects/testbed/test-db-for-hibernate-create-drop

您可以自己尝试:

git clone git@github.com:zzantozz/testbed tmpcd tmpmvn compile exec:java -Dexec.mainClass=rds.hibernate.Main -pl hibernate-create-drop


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/447624.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号