Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

org.hibernate.exception.SQLGrammarException: could not insert:

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting this error. i am using hibernate with derby database on eclipse. please any suggestions would be appreciated.


08:01:40,106 INFO Version:15 - Hibernate Annotations 3.4.0.GA
08:01:40,134 INFO Environment:560 - Hibernate 3.3.2.GA
08:01:40,144 INFO Environment:593 - hibernate.properties not found
08:01:40,150 INFO Environment:771 - Bytecode provider name : javassist
08:01:40,157 INFO Environment:652 - using JDK 1.4 java.sql.Timestamp handling
08:01:40,290 INFO Version:14 - Hibernate Commons Annotations 3.1.0.GA
08:01:40,305 INFO Configuration:1474 - configuring from resource: hibernate.cfg.xml
08:01:40,306 INFO Configuration:1451 - Configuration resource: hibernate.cfg.xml
08:01:40,448 INFO Configuration:1589 - Configured SessionFactory: null
08:01:40,484 INFO Dialect:175 - Using dialect: org.hibernate.dialect.DerbyDialect
08:01:40,653 INFO AnnotationBinder:419 - Binding entity from annotated class: com.hibernate.ch2.School
08:01:40,711 INFO EntityBinder:422 - Bind entity com.hibernate.ch2.School on table School
08:01:40,799 INFO AnnotationConfiguration:369 - Hibernate Validator not found: ignoring
08:01:40,885 INFO SchemaExport:226 - Running hbm2ddl schema export
08:01:40,886 DEBUG SchemaExport:242 - import file not found: /import.sql
08:01:40,886 INFO SchemaExport:251 - exporting generated schema to database
08:01:40,890 INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
08:01:40,891 INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 2
08:01:40,891 INFO DriverManagerConnectionProvider:68 - autocommit mode: false
08:01:40,912 INFO DriverManagerConnectionProvider:103 - using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/HibernateDb;create=true
08:01:40,912 INFO DriverManagerConnectionProvider:109 - connection properties: {user=vicky, password=****}
drop table School
08:01:41,217 DEBUG SchemaExport:377 - drop table School
08:01:41,263 DEBUG SchemaExport:362 - Unsuccessful: drop table School
08:01:41,264 DEBUG SchemaExport:363 - 'DROP TABLE' cannot be performed on 'SCHOOL' because it does not exist.
drop table hibernate_unique_key
08:01:41,264 DEBUG SchemaExport:377 - drop table hibernate_unique_key
create table School (schoolId integer not null, public smallint not null, schoolAddress varchar(255), studentCount integer not null, schoolName varchar(255), primary key (schoolId))
08:01:41,350 DEBUG SchemaExport:377 - create table School (schoolId integer not null, public smallint not null, schoolAddress varchar(255), studentCount integer not null, schoolName varchar(255), primary key (schoolId))
08:01:41,368 ERROR SchemaExport:348 - Unsuccessful: create table School (schoolId integer not null, public smallint not null, schoolAddress varchar(255), studentCount integer not null, schoolName varchar(255), primary key (schoolId))
08:01:41,368 ERROR SchemaExport:349 - Syntax error: Encountered "public" at line 1, column 49.
create table hibernate_unique_key ( next_hi integer )
08:01:41,368 DEBUG SchemaExport:377 - create table hibernate_unique_key ( next_hi integer )
insert into hibernate_unique_key values ( 0 )
08:01:41,427 DEBUG SchemaExport:377 - insert into hibernate_unique_key values ( 0 )
08:01:41,438 INFO SchemaExport:268 - schema export complete
08:01:41,440 INFO DriverManagerConnectionProvider:170 - cleaning up connection pool: jdbc:derby://localhost:1527/HibernateDb;create=true
08:01:41,448 INFO HibernateSearchEventListenerRegister:53 - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
08:01:41,559 INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
08:01:41,560 INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 2
08:01:41,560 INFO DriverManagerConnectionProvider:68 - autocommit mode: false
08:01:41,560 INFO DriverManagerConnectionProvider:103 - using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/HibernateDb;create=true
08:01:41,561 INFO DriverManagerConnectionProvider:109 - connection properties: {user=vicky, password=****}
08:01:41,573 INFO SettingsFactory:114 - RDBMS: Apache Derby, version: 10.8.2.2 - (1181258)
08:01:41,574 INFO SettingsFactory:115 - JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.8.2.2 - (1181258)
08:01:41,596 INFO Dialect:175 - Using dialect: org.hibernate.dialect.DerbyDialect
08:01:41,649 INFO TransactionFactoryFactory:59 - Using default transaction strategy (direct JDBC transactions)
08:01:41,652 INFO TransactionManagerLookupFactory:80 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
08:01:41,652 INFO SettingsFactory:161 - Automatic flush during beforeCompletion(): disabled
08:01:41,653 INFO SettingsFactory:165 - Automatic session close at end of transaction: disabled
08:01:41,654 INFO SettingsFactory:180 - Scrollable result sets: enabled
08:01:41,654 INFO SettingsFactory:188 - JDBC3 getGeneratedKeys(): disabled
08:01:41,655 INFO SettingsFactory:196 - Connection release mode: auto
08:01:41,656 INFO SettingsFactory:223 - Default batch fetch size: 1
08:01:41,656 INFO SettingsFactory:227 - Generate SQL with comments: disabled
08:01:41,657 INFO SettingsFactory:231 - Order SQL updates by primary key: disabled
08:01:41,657 INFO SettingsFactory:235 - Order SQL inserts for batching: disabled
08:01:41,657 INFO SettingsFactory:397 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
08:01:41,660 INFO ASTQueryTranslatorFactory:47 - Using ASTQueryTranslatorFactory
08:01:41,660 INFO SettingsFactory:243 - Query language substitutions: {}
08:01:41,661 INFO SettingsFactory:248 - JPA-QL strict compliance: disabled
08:01:41,661 INFO SettingsFactory:253 - Second-level cache: enabled
08:01:41,661 INFO SettingsFactory:257 - Query cache: disabled
08:01:41,669 INFO SettingsFactory:382 - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
08:01:41,670 INFO RegionFactoryCacheProviderBridge:61 - Cache provider: org.hibernate.cache.NoCacheProvider
08:01:41,670 INFO SettingsFactory:267 - Optimize cache for minimal puts: disabled
08:01:41,670 INFO SettingsFactory:276 - Structured second-level cache entries: disabled
08:01:41,677 INFO SettingsFactory:296 - Echoing all SQL to stdout
08:01:41,679 INFO SettingsFactory:305 - Statistics: disabled
08:01:41,679 INFO SettingsFactory:309 - Deleted entity synthetic identifier rollback: disabled
08:01:41,679 INFO SettingsFactory:324 - Default entity-mode: pojo
08:01:41,680 INFO SettingsFactory:328 - Named query checking : enabled
08:01:41,737 INFO SessionFactoryImpl:193 - building session factory
08:01:41,979 INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured
Hibernate: insert into School (public, schoolAddress, studentCount, schoolName, schoolId) values (?, ?, ?, ?, ?)
08:01:42,190 WARN JDBCExceptionReporter:100 - SQL Error: -1, SQLState: 42X01
08:01:42,191 ERROR JDBCExceptionReporter:101 - Syntax error: Encountered "public" at line 1, column 21.
08:01:42,193 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [com.hibernate.ch2.School]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2285)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2678)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.hibernate.ch2.TestSchool.main(TestSchool.java:36)
Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "public" at line 1, column 21.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2242)
... 11 more
Caused by: org.apache.derby.client.am.SqlException: Syntax error: Encountered "public" at line 1, column 21.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
... 17 more
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.hibernate.ch2.School]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2285)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2678)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.hibernate.ch2.TestSchool.main(TestSchool.java:36)
Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "public" at line 1, column 21.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2242)
... 11 more
Caused by: org.apache.derby.client.am.SqlException: Syntax error: Encountered "public" at line 1, column 21.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
... 17 more


and that is my configuration file


and below is my code

School.java


SchoolDetail.java

and finally this is TestSchool.java
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since i never use Derby i'm not sure that this answer is correct but the problem you are having may be because you are using the word "public" as a table column which may be a reserverd database word. Try to use publicSchool instead of public as column name and in your application.
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bogdan is correct.

Check this page for a list of all Derby reserved words:

http://db.apache.org/derby/docs/10.1/ref/rrefkeywords29722.html

Pat.
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!