为了账号安全,请及时绑定邮箱和手机立即绑定

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

如题,<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 回答

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



0 回复 有任何疑惑可以回复我~
#1

迷失代码林 提问者

非常感谢!
2017-05-09 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信