2011-03-04 98 views
0

iam执行eclipse中的hibernate anotation示例galileo iam出现以下错误。休眠注释

Hibernate: insert into employee1 (Name, ID) values (?, ?) 
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update 
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) 
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) 
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253) 
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237) 
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141) 
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) 
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) 
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) 
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) 
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) 
    at net.roseindia.Example1.main(Example1.java:22) 
Caused by: java.sql.BatchUpdateException: Table 'test.employee1' doesn't exist 
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1566) 
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) 
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246) 
    ... 8 more
+6

您是否真的创建了数据库? <*表'test.employee1'不存在* – 2011-03-04 08:21:42

回答

2

产生的原因:java.sql.BatchUpdateException:表 'test.employee1' 不存在

这意味着,如果你想休眠的表不存在:-)自动创建和删除表格,将属性hibernate.hbm2ddl.auto设置为create-drop。另外,我建议阅读Hibernate文档,因为它是初学者最好的资源之一。

http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/configuration.html#setup-configuration

+0

+1对于自动表格创建有很好的建议。 – Nilesh 2011-03-04 10:35:11