What’s wrong with running Hibernate Query?

Asked

Viewed 94 times

0

I am running this query in Hibernate:

manager.createQuery("from Usuario where senha = '" + senha + "' and login = '" + login + "'", Usuario.class).getResultList();

But is giving an Exception that one of the columns does not exist in the BD, but the same is in the table!!!!

What could I be doing wrong?

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'usuario0_.telefone' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2030)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
  • I never used Hibernate, but look what he says in the first line Unknown column 'usuario0_.telefone' in 'field list'. You don’t have a problem with your mapping? Maybe you’ve deleted some field, something like that.

  • Jéferson, I already found out. In the table the name of the field is tefefone. I switched the "t" with the "f". Thanks

1 answer

1


Check out the first line of stack trace

Unknown column 'usuario0_.telefone' in 'field list'

That means Hibernate couldn’t find his spine telefone, check if the name is not wrong or you have not deleted this field.

  • I changed a character, corrected and everything went back to normal. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.