hibernate配置文件中的htm2ddl.auto屬性設(shè)置為create,但是生成對(duì)象到數(shù)據(jù)庫(kù)時(shí)是累加的
如題,<property name="htm2ddl.auto">create</property><!-- DDL語(yǔ)句生成策略 -->配置文件中是這么寫的,不過(guò)每生成一個(gè)對(duì)象,并不像視頻中說(shuō)的那樣會(huì)把數(shù)據(jù)庫(kù)中的表刪掉重建,而是將對(duì)象直接插入到表中。
以下是控制臺(tái)顯示的全部?jī)?nèi)容
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
? ? ? ? (?)
2017-05-09
<property name="hbm2ddl.auto">create</property>這句你寫錯(cuò)了,是hbm2ddl.auto不是html2ddl.auto??!
2017-05-05
我是參照視頻里的操作的,這應(yīng)該沒(méi)什么問(wèn)題吧,但是結(jié)果就是這樣,生成幾次就有幾個(gè)對(duì)象保存到數(shù)據(jù)庫(kù)中了,而視頻中只存在一個(gè)對(duì)象,舊的會(huì)被刪掉。
2017-05-05
是不是你單元測(cè)試運(yùn)行錯(cuò)了呀,你的調(diào)試信息是 Insert 語(yǔ)句,正常情況應(yīng)該是?create 語(yǔ)句