日期:2014-05-18  浏览次数:20651 次

用hibernate连接my sql的问题?
编译可以通过,但运行时候出现超多的问题..盼高人指教!!!
log4j:WARN   No   appenders   could   be   found   for   logger   (org.hibernate.cfg.Environment).
log4j:WARN   Please   initialize   the   log4j   system   properly.
Exception   in   thread   "main "   org.hibernate.exception.SQLGrammarException:   could   not   get   or   update   next   value
at   org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at   org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at   org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:85)
at   org.hibernate.id.TableGenerator.generate(TableGenerator.java:94)
at   org.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:61)
at   org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at   org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at   org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at   org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:516)
at   org.hibernate.impl.SessionImpl.save(SessionImpl.java:506)
at   org.hibernate.impl.SessionImpl.save(SessionImpl.java:502)
at   dao.UserDaoImpl.addUser(UserDaoImpl.java:12)
at   demo.Demo.main(Demo.java:17)
Caused   by:   java.sql.SQLException:   Table   'adam.hi_value '   doesn 't   exist
at   com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
at   com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at   com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at   com.mysql.jdbc.Connection.execSQL(Connection.java:2376)
at   com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at   com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860)
at   com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1705)
at   org.hibernate.id.TableGenerator.doWorkInCurrentTransaction(TableGenerator.java:133)
at   org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:64)
...   13   more


------解决方案--------------------
提示的很明显啊,你的hsql语句有语法错误,转化成sql语句后没找到adam.hi_value这个表。

把hibernate的显示sql语句设置为true,然后看转化成什么sql语句了,然后把这个语句在mysql客户端执行一下看看。

如果你不存在拼写错误的话,那么就把adam.hi_value改为hi_value试试
------解决方案--------------------
首先看一下配置文件中关于数据库的配置信息是否正确,
其次,看看这个报的错:
Caused by: java.sql.SQLException: Table 'adam.hi_value ' doesn 't exist
------
表 'adam.hi_value是不是没有创建?