Win a copy of Event Streams in Action this week in the Java in General forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Hibernate SQLGrammarException

Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator

I am facing a problem when I try to run this code.

=================My Entity Class==================
@NamedNativeQuery(name = "Vehicle.byName", query = "select * from VEHICLE where VEHICLE_NAME = ?", resultClass=Vehicle.class)
public class Vehicle{
private static final long serialVersionUID = 1L;

@Id @GeneratedValue(strategy=GenerationType.AUTO)
private int vehicleId;

private String vehicleName;

//Getters and Setters......

==================My hibernate.cfg.xml is as below==================

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernatedb</property>
<property name="connection.username">root</property>
<property name="connection.password">*********</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="">update</property>

<!-- Names the annotated entity class -->
<mapping class="org.saikat.javaapps.hibernate.Vehicle"/>

=======My Service class========================

public class GetVehicle {

* @param args
public static void main(String[] args) {
SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();

Query query = session.getNamedQuery("Vehicle.byName");
query.setString(0, "Porshe");
List<Vehicle> vehicleList = (List<Vehicle>)query.list();

for(Vehicle v : vehicleList){
System.out.println("Vehicle retrieved is " + v.getVehicleName());
My database structure is like below.


Now the problem is when I try to run the service method it throws an error like,


SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Hibernate: select * from VEHICLE where VEHICLE_NAME = ?
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.loader.Loader.doList(
at org.hibernate.loader.Loader.listIgnoreQueryCache(
at org.hibernate.loader.Loader.list(
at org.hibernate.loader.custom.CustomLoader.list(
at org.hibernate.impl.SessionImpl.listCustomQuery(
at org.hibernate.impl.AbstractSessionImpl.list(
at org.hibernate.impl.SQLQueryImpl.list(
at org.saikat.javaapps.service.GetVehicle.main(
Caused by: java.sql.SQLException: Column 'clazz_' not found.
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.ResultSet.findColumn(
at com.mysql.jdbc.ResultSet.getInt(
at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(
at org.hibernate.loader.Loader.getInstanceClass(
at org.hibernate.loader.Loader.instanceNotYetLoaded(
at org.hibernate.loader.Loader.getRow(
at org.hibernate.loader.Loader.getRowFromResultSet(
at org.hibernate.loader.Loader.doQuery(
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(
at org.hibernate.loader.Loader.doList(
... 7 more


Please, give me the expected solution.

Posts: 4101
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please continue the discussion in your other thread. And please don't duplicate posts in the forums (CarefullyChooseOneForum).
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!