Hibernate 自动生成表问题

  在hibernate4.2.4中使用MySQLInnoDBDialect方言和hibernate.hbm2ddl.auto为update自动生成表时报错,我的 mysql版本为5.5,报错如下:

二月 16, 2017 5:33:28 下午 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
二月 16, 2017 5:33:28 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.4.Final}
二月 16, 2017 5:33:28 下午 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
二月 16, 2017 5:33:28 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
二月 16, 2017 5:33:29 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
二月 16, 2017 5:33:29 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
二月 16, 2017 5:33:29 下午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: hibernate/Customer.hbm.xml
二月 16, 2017 5:33:29 下午 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!
二月 16, 2017 5:33:29 下午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: hibernate/Order.hbm.xml
二月 16, 2017 5:33:29 下午 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!
二月 16, 2017 5:33:29 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
二月 16, 2017 5:33:29 下午 org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator instantiateExplicitConnectionProvider
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
二月 16, 2017 5:33:29 下午 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/student
二月 16, 2017 5:33:29 下午 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000046: Connection properties: {user=root, password=****}
二月 16, 2017 5:33:29 下午 org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider configure
INFO: HHH000006: Autocommit mode: false
二月 16, 2017 5:33:29 下午 com.mchange.v2.log.MLog <clinit>
信息: MLog clients using java 1.4+ standard logging.
二月 16, 2017 5:33:30 下午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
二月 16, 2017 5:33:30 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@8c722a7b [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@aead7dbf [ acquireIncrement -> 2, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hgf6yt9mjhwgtfebvo9c|7f3b2ece, idleConnectionTestPeriod -> 2000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 2000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 10, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@ff768db0 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hgf6yt9mjhwgtfebvo9c|7921dcac, jdbcUrl -> jdbc:mysql://localhost:3306/student, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hgf6yt9mjhwgtfebvo9c|4c082ab3, numHelperThreads -> 3 ]
二月 16, 2017 5:33:31 下午 org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
二月 16, 2017 5:33:31 下午 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
二月 16, 2017 5:33:31 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
二月 16, 2017 5:33:31 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: CUSTOMER
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: ORDERS
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: CUSTOMER
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: ORDERS
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: CUSTOMER
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: ORDERS
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: HHH000388: Unsuccessful: create table CUSTOMER (CUSTOMER_ID integer not null auto_increment, CUSTOMER_NAME varchar(255), primary key (CUSTOMER_ID)) type=InnoDB
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 5
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: HHH000388: Unsuccessful: create table ORDERS (ORDER_ID integer not null auto_increment, ORDER_NAME varchar(255), CUSTOMER_ID integer, primary key (ORDER_ID)) type=InnoDB
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 6
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: HHH000388: Unsuccessful: alter table ORDERS add index FK_57wwsm6wqqkcr1amp4dtsk5bs (CUSTOMER_ID), add constraint FK_57wwsm6wqqkcr1amp4dtsk5bs foreign key (CUSTOMER_ID) references CUSTOMER (CUSTOMER_ID)
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: Table 'student.orders' doesn't exist
二月 16, 2017 5:33:32 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
解决办法为:

  我将MySQLInnoDBDialect方言配置改为了MySQ5LInnoDBDialect就好了,hibernate中关于mysql的配置属性常量里面没有此方言,eclipse插件中有这个选项。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雅静8

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值