hibernate配置文件中的htm2ddl.auto属性设置为create,但是生成对象到数据库时是累加的

来源:2-2 hibernate常用配置

迷失代码林

2017-05-05 20:20

如题,<property name="htm2ddl.auto">create</property><!-- DDL语句生成策略 -->配置文件中是这么写的,不过每生成一个对象,并不像视频中说的那样会把数据库中的表删掉重建,而是将对象直接插入到表中。

以下是控制台显示的全部内容

2017-5-5 20:09:09 org.hibernate.annotations.common.Version <clinit>

INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}

2017-5-5 20:09:09 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.2.4.Final}

2017-5-5 20:09:09 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

2017-5-5 20:09:09 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

2017-5-5 20:09:09 org.hibernate.cfg.Configuration configure

INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml

2017-5-5 20:09:09 org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml

2017-5-5 20:09:09 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity

WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

2017-5-5 20:09:09 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: User.hbm.xml

2017-5-5 20:09:09 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity

WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

2017-5-5 20:09:09 org.hibernate.cfg.Configuration doConfigure

INFO: HHH000041: Configured SessionFactory: null

2017-5-5 20:09:09 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)

2017-5-5 20:09:09 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000115: Hibernate connection pool size: 20

2017-5-5 20:09:09 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000006: Autocommit mode: false

2017-5-5 20:09:09 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:orcl]

2017-5-5 20:09:09 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000046: Connection properties: {user=MKADMIN, password=****}

2017-5-5 20:09:09 org.hibernate.dialect.Dialect <init>

INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect

2017-5-5 20:09:09 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation

INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

2017-5-5 20:09:09 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService

INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)

2017-5-5 20:09:09 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>

INFO: HHH000397: Using ASTQueryTranslatorFactory

Hibernate: 

    insert 

    into

        users

        (username) 

    values

        (?)


写回答 关注

3回答

  • 阿阿金
    2017-05-09 09:35:12
    已采纳

    <property name="hbm2ddl.auto">create</property>这句你写错了,是hbm2ddl.auto不是html2ddl.auto啊!



    迷失代码林

    非常感谢!

    2017-05-09 12:43:17

    共 1 条回复 >

  • 迷失代码林
    2017-05-05 22:21:15

    我是参照视频里的操作的,这应该没什么问题吧,但是结果就是这样,生成几次就有几个对象保存到数据库中了,而视频中只存在一个对象,旧的会被删掉。

  • 梦巷鱼儿
    2017-05-05 22:18:26

    是不是你单元测试运行错了呀,你的调试信息是 Insert 语句,正常情况应该是 create 语句

Hibernate初探之单表映射

Java持久化框架Hibernate入门教程,掌握Hibernate基本概念

74810 学习 · 793 问题

查看课程

相似问题