org.hibernate.exception.SQLGrammarException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • The following test: public void test2(){ List<Storage> storages= getSF().openSession().createCriteria(Storage.class).list(); System.out.println("Storages:"); for(Storage storage:storages){ System.out.println(" - "+storage); Map<Product,Quantity> products=storage.getProductQuantity(); for(Product p:products.keySet()) System.out.println(" - - "+p+" "+products.get(p)); } @Entity @AccessType("field") public class Storage{ @Id protected int id; protected String name; @MapKey @OneToMany(cascade=CascadeType.ALL) protected Map<Product,Quantity> productQuantity=new HashMap<Product,Quantity>(); public Map<Product, Quantity> getProductQuantity(){ return productQuantity; } public void addProduct(Product product,Quantity quantity){ productQuantity.put(product,quantity); } Storage(){ } public Storage(String name){ this.name=name; id=hashCode(); } public String toString(){ return name; } } this class (Storage.class) persists perfectly (checked thru pgAdmin III), the name field is fetched, but when trying to fetch Map: for(Product p:products.keySet()) it fails with that kind of listing: Storages: - Main storage 12:04:36,154 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 42703 12:04:36,154 ERROR JDBCExceptionReporter:72 - ERROR: column productqua0_.id does not exist Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not initialize a collection: [Storage.productQuantity#779317485] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.loadCollection(Loader.java:1926) at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520) at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60) at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1693) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentMap.keySet(PersistentMap.java:190) at PTest.listStorage(Ptest.java:87) at PTest..test2(Ptest.java:80) at Ptest.<init>(Ptest.java:20) at Ptest.main(Ptest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86) Caused by: org.postgresql.util.PSQLException: ERROR: column productqua0_.id does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1501) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1286) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:177) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139) at org.hibernate.loader.Loader.getResultSet(Loader.java:1669) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.loadCollection(Loader.java:1919) ... 16 more PS I've set priority to Critical, since it's really critical for me. It would be hard to write all the code now with Sets, which work fine, but the data structure is really ugly, and later refactor everything to Maps
    via by Philipp Pirozhkov,
  • The following test: public void test2(){ List<Storage> storages= getSF().openSession().createCriteria(Storage.class).list(); System.out.println("Storages:"); for(Storage storage:storages){ System.out.println(" - "+storage); Map<Product,Quantity> products=storage.getProductQuantity(); for(Product p:products.keySet()) System.out.println(" - - "+p+" "+products.get(p)); } @Entity @AccessType("field") public class Storage{ @Id protected int id; protected String name; @MapKey @OneToMany(cascade=CascadeType.ALL) protected Map<Product,Quantity> productQuantity=new HashMap<Product,Quantity>(); public Map<Product, Quantity> getProductQuantity(){ return productQuantity; } public void addProduct(Product product,Quantity quantity){ productQuantity.put(product,quantity); } Storage(){ } public Storage(String name){ this.name=name; id=hashCode(); } public String toString(){ return name; } } this class (Storage.class) persists perfectly (checked thru pgAdmin III), the name field is fetched, but when trying to fetch Map: for(Product p:products.keySet()) it fails with that kind of listing: Storages: - Main storage 12:04:36,154 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 42703 12:04:36,154 ERROR JDBCExceptionReporter:72 - ERROR: column productqua0_.id does not exist Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not initialize a collection: [Storage.productQuantity#779317485] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.loadCollection(Loader.java:1926) at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520) at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60) at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1693) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentMap.keySet(PersistentMap.java:190) at PTest.listStorage(Ptest.java:87) at PTest..test2(Ptest.java:80) at Ptest.<init>(Ptest.java:20) at Ptest.main(Ptest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86) Caused by: org.postgresql.util.PSQLException: ERROR: column productqua0_.id does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1501) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1286) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:177) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139) at org.hibernate.loader.Loader.getResultSet(Loader.java:1669) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.loadCollection(Loader.java:1919) ... 16 more PS I've set priority to Critical, since it's really critical for me. It would be hard to write all the code now with Sets, which work fine, but the data structure is really ugly, and later refactor everything to Maps
    via by Philipp Pirozhkov,
  • jtrac issues w/ UNIX and ORACLE
    via j-trac by hkansal
    ,
  • Hibernate/Oracle Sequence not working
    via Stack Overflow by Paul
    ,
  • Could not execute JDBC batch update
    via Stack Overflow by Krish
    ,
    • org.hibernate.exception.SQLGrammarException: could not initialize a collection: [Storage.productQuantity#779317485] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.loadCollection(Loader.java:1926) at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520) at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60) at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1693) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentMap.keySet(PersistentMap.java:190) at PTest.listStorage(Ptest.java:87)

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    2 more bugmates