2013年11月17日星期日

Hibernate automatically creates the table driving me crazy

Driving me crazy how Hibernate can not automatically create table
set true
create
corresponding sql statement in the console are also displayed, and how is the automatic construction of the table can not . . I tried the built in mysql table first , and then insert the data, so that not a little problem . . . This is the wisdom situation ? ? ?
the following error:
November 13 , 2011 8:50:45 PM org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons Annotations {4.0.0.CR2}
November 13 , 2011 8:50:45 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.0.0.CR5}
November 13 , 2011 8:50:45 PM org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
November 13 , 2011 8:50:45 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name: javassist
November 13 , 2011 8:50:45 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: / hibernate.cfg.xml
November 13 , 2011 8:50:45 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: / hibernate.cfg.xml
November 13 , 2011 8:50:46 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: org / crazyit / app / domain / News.hbm.xml
November 13 , 2011 8:50:46 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
November 13 , 2011 8:50:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
November 13 , 2011 8:50:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
November 13 , 2011 8:50:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
November 13 , 2011 8:50:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc: mysql :/ / localhost: 3306/hibernate]
November 13 , 2011 8:50:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user = root, password = ****}
November 13 , 2011 8:50:46 PM org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
November 13 , 2011 8:50:46 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
November 13 , 2011 8:50:46 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
November 13 , 2011 8:50:47 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Hibernate: drop table if exists news_table
Hibernate: create table news_table (newid integer not null auto_increment, title varchar (255), content varchar (255), primary key ( newid)) type = InnoDB
November 13 , 2011 8:50:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create table news_table (newid integer not null auto_increment, title varchar (255), content varchar (255) , primary key (newid)) type = InnoDB
November 13 , 2011 8:50:47 PM org.hibernate.internal.CoreMessageLogger_ $ logger error
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 1
November 13 , 2011 8:50:47 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Hibernate: insert into news_table (title, content) values ​​(?,?)
November 13 , 2011 8:50:47 PM org.hibernate.internal.CoreMessageLogger_ $ logger warn
WARN: SQL Error: 1146, SQLState: 42S02
November 13 , 2011 8:50:47 PM org.hibernate.internal.CoreMessageLogger_ $ logger error
ERROR: Table 'hibernate.news_table' doesn't exist
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Table 'hibernate.news_table' doesn't exist
at org.hibernate.exception.internal.SQLStateConverter.convert (SQLStateConverter.java: 100)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert (SqlExceptionHelper.java: 125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert (SqlExceptionHelper.java: 110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation (AbstractStatementProxyHandler.java: 129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke (AbstractProxyHandler.java: 81)
at $ Proxy5.executeUpdate (Unknown Source)
at org.hibernate.id.IdentityGenerator $ GetGeneratedKeysDelegate.executeAndExtract (IdentityGenerator.java: 96)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert (AbstractReturningDelegate.java: 55)
at org.hibernate.persister.entity.AbstractEntityPersister.insert (AbstractEntityPersister.java: 2757)
at org.hibernate.persister.entity.AbstractEntityPersister.insert (AbstractEntityPersister.java: 3268)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute (EntityIdentityInsertAction.java: 78)
at org.hibernate.engine.spi.ActionQueue.execute (ActionQueue.java: 273)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate (AbstractSaveEventListener.java: 304)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave (AbstractSaveEventListener.java: 195)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId (AbstractSaveEventListener.java: 128)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId (DefaultSaveOrUpdateEventListener.java: 204)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId (DefaultSaveEventListener.java: 55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient (DefaultSaveOrUpdateEventListener.java: 189)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate (DefaultSaveEventListener.java: 49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate (DefaultSaveOrUpdateEventListener.java: 90)
at org.hibernate.internal.SessionImpl.fireSave (SessionImpl.java: 646)
at org.hibernate.internal.SessionImpl.save (SessionImpl.java: 639)
at org.hibernate.internal.SessionImpl.save (SessionImpl.java: 635)
at lee.NewsManager.main (NewsManager.java: 32)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernate.news_table' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance (Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (Unknown Source)
at java.lang.reflect.Constructor.newInstance (Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance (Util.java: 411)
at com.mysql.jdbc.Util.getInstance (Util.java: 386)
at com.mysql.jdbc.SQLError.createSQLException (SQLError.java: 1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket (MysqlIO.java: 3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket (MysqlIO.java: 3541)
at com.mysql.jdbc.MysqlIO.sendCommand (MysqlIO.java: 2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect (MysqlIO.java: 2163)
at com.mysql.jdbc.ConnectionImpl.execSQL (ConnectionImpl.java: 2624)
at com.mysql.jdbc.PreparedStatement.executeInternal (PreparedStatement.java: 2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate (PreparedStatement.java: 2427)
at com.mysql.jdbc.PreparedStatement.executeUpdate (PreparedStatement.java: 2345)
at com.mysql.jdbc.PreparedStatement.executeUpdate (PreparedStatement.java: 2330)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source)
at java.lang.reflect.Method.invoke (Unknown Source)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation (AbstractStatementProxyHandler.java: 122)
... 20 more

------ Solution ------------------------------------ --------
direct execution ExportDB class
------ Solution ------------------------- -------------------
news_table this entity class in question , stickers.
also on HIBERANTE comments configuration , then also put your new_table this entity class configured to hiberante configuration file.
------ Solution ---------------------------------------- ----
agree upstairs
------ Solution ------------------------------ --------------
trance remember a man named xxx .. hbm.xml file schema stuff, delete try
------ For reference only ---------------------------------------
table should be built up , the first execution will build the table , after each table will still be built , but will delete the original table , try to create this into update ( updates the table exists , does not exist is created ), LZ try
------ For reference only ---------------------------------------

useless ah have tried update, create, create_drop; never starting . . . Hey
------ For reference only ----------------------------------- ----
you did not build the database beforehand ? ? ?
------ For reference only -------------------------------------- -

built the database is not the problem
------ For reference only ------------------- --------------------

not through annotation configuration. . . .
entity class as follows
package org.crazyit.app.domain;

public class News {
private Integer id;
private String title;
private String content;

public Integer getId () {
return id;
}
public void setId (Integer id) {
this.id = id;
}

public String getTitle () {
return title;
}
public void setTitle (String title) {
this.title = title;
}

public String getContent () {
return content;
}
public void setContent (String content) {
this.content = content;
}
}

------ For reference only ---------------------------------- -----

me this is entirely that of the Gang lightweight j2ee about hibernate in the first example of a move over . . . Just changed some connection mysql database connection parameters, and created a database to operate . . . Unreasonable not automatically create a new data table ah , but that in mysql new table, and then insert the data via hibernate , you can perform , this wonder
------ For reference only ---- -----------------------------------
young too impetuous.
------ For reference only -------------------------------------- -
ask your project team of people, you configure this wrong .
------ For reference only -------------------------------------- -
I encountered the same situation with you , but also examples of exercises Gang links MYSQL database , you can not create a table ERROR: HHH000389: Unsuccessful: create table news_table (id integer not null auto_increment, title varchar (255), content varchar (255), primary key (id)) type = InnoDB.
------ For reference only -------------------------------------- -
Hello ! I also encountered the same problem with you . In hibernate.cfg.xml dialect of the database to org.hibernate.dialect.MySQLDialect from org.hibernate.dialect.MySQLInnoDBDialect resolved after that you can try.
------ For reference only -------------------------------------- -
sick of it, encountered this problem tangle

没有评论:

发表评论