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
? ? ? ? (?)
2017-05-09
<property name="hbm2ddl.auto">create</property>這句你寫錯了,是hbm2ddl.auto不是html2ddl.auto??!
2017-05-05
我是參照視頻里的操作的,這應該沒什么問題吧,但是結果就是這樣,生成幾次就有幾個對象保存到數據庫中了,而視頻中只存在一個對象,舊的會被刪掉。
2017-05-05
是不是你單元測試運行錯了呀,你的調試信息是 Insert 語句,正常情況應該是?create 語句