hibernate的错误

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 'from Student' at line 1
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
	at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:2115)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1874)
	at org.hibernate.loader.Loader.doQuery(Loader.java:919)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
	at org.hibernate.loader.Loader.doList(Loader.java:2610)
	at org.hibernate.loader.Loader.doList(Loader.java:2593)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
	at org.hibernate.loader.Loader.list(Loader.java:2417)
	at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:336)
	at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1980)
	at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)
	at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)
	at com.test.hibernateutils.findall(hibernateutils.java:67)
	at com.test.test.main(test.java:14)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'from Student' at line 1
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2487)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
	... 15 more

检查原因是   java.util.List<Student> list=   session.createSQLQuery("from Student").list();

应该是 java.util.List<Student>list=session.createQuery(“form Student”).list()

以此警示

猜你喜欢

转载自blog.csdn.net/zhunquanjiong6199/article/details/82182277