-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: SQLGrammarException using PostgreSQL 8.0.4
PostPosted: Thu Oct 20, 2005 12:44 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Hibernate version:3.0.5

Mapping documents:

Code between sessionFactory.openSession() and session.close():

session = HibernateUtil.currentSession();
tx = session.beginTransaction();

ChangeCase aChangeCase = new ChangeCase();
aChangeCase.setChangeCaseId(new Integer(1));
aChangeCase.setEndPos(new Integer(10));
aChangeCase.setStartPos(new Integer(1));
aChangeCase.setOrigText("TEST TEXT");
aChangeCase.setProblemText("MORE TEST TEXT");
aChangeCase.setChangeDt(new Date());

session.save(aChangeCase);
tx.commit();
session.close();



Full stack trace of any exception that occurs:

org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.synesis7.i3.versioncontrol.TPDR.testTpdr(TPDR.java:45)
at com.synesis7.i3.versioncontrol.TPDR.main(TPDR.java:20)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into public.ChangeCase (StartPos, EndPos, ChangeDt, OrigText, ProblemText, ChangeCaseId) values (1, 10, 2005-10-19, TEST TEXT, MORE TEST TEXT, 1) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2396)
at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:386)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1257)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:334)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2455)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 9 more




Name and version of the database you are using:PostgreSQL 8.0.4

The generated SQL (show_sql=true):Hibernate: insert into public.ChangeCase (StartPos, EndPos, ChangeDt, OrigText, ProblemText, ChangeCaseId) values (?, ?, ?, ?, ?, ?)


I would appreciate any input on this problem. Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 12:53 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
it looks like ChangeCase is mapped to the "public.ChangeCase" table. if so, try removing the schema prefix.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:06 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Dennis,

Thank you for your answer. Unfortunately, that didn't fix the problem.

The same error still remains. :(

The stacktrace remained the same. Minus the public. prefix :(


Hibernate: insert into ChangeCase (StartPos, EndPos, ChangeDt, OrigText, ProblemText, ChangeCaseId) values (?, ?, ?, ?, ?, ?)
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.synesis7.i3.versioncontrol.TPDR.testTpdr(TPDR.java:45)
at com.synesis7.i3.versioncontrol.TPDR.main(TPDR.java:20)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into ChangeCase (StartPos, EndPos, ChangeDt, OrigText, ProblemText, ChangeCaseId) values (1, 10, 2005-10-19, TEST TEXT, MORE TEST TEXT, 1) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2396)
at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:386)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1257)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:334)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2455)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
... 9 more



Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:25 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
what happens if you try running that sql in plain jdbc ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:37 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Well, in regular JDBC with some altering it works. Like surrounding the string fields w/ single qoutes like 'TEST TEXT'

I would assume that Hibernate is taking care of issues like that though. Am I wrong? If so, I can handle varchar fields fine, but then there is the issue of date fields.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:50 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
that's weird. can you post the mapping document for this class?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:54 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Gladly!!!

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="com.synesis7.i3.versioncontrol.ChangeCase" table="ChangeCase">
<id name="changeCaseId" type="integer">
<column name="ChangeCaseId" />
<generator class="assigned" />
</id>
<property name="startPos" type="integer">
<column name="StartPos" />
</property>
<property name="endPos" type="integer">
<column name="EndPos" />
</property>
<property name="changeDt" type="date">
<column name="ChangeDt" length="4" />
</property>
<property name="origText" type="string">
<column name="OrigText" length="4000" not-null="true" />
</property>
<property name="problemText" type="string">
<column name="ProblemText" length="1056" />
</property>
<set name="changeDocs" inverse="true">
<key>
<column name="ChangeCaseId" not-null="true" />
</key>
<one-to-many class="com.synesis7.i3.versioncontrol.ChangeDoc" />
</set>
</class>
</hibernate-mapping>


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:05 am 
Newbie

Joined: Mon Aug 30, 2004 1:37 am
Posts: 16
Just a couple of quick suggestions to help determine what postgresql is getting upset about:
check your application log for occurrences of
Quote:
org.hibernate.util.JDBCExceptionReporter
- if reported this should indicate what is causing the problem.
If not and if you have control over your postgresql installation, you can set it to log all statements sent to it, then check the postgresql log to see what it was sent and what it considers to be wrong with it. To do this add
Code:
log_statement = 'all'
to postgresql.conf, restart the server, run your test and then examine pgsql.log.
Good luck.
Grainne.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:17 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Here is what I see in the log...

2005-10-20 00:16:26 LOG: unexpected EOF on client connection

2005-10-20 00:16:46 ERROR: relation "changecase" does not exist

2005-10-20 00:16:46 LOG: could not receive data from client: No connection could be made because the target machine actively refused it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:26 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
I have checked and double checked...

my username and password are correct in my cfg file.
The table ChangeCase does in fact exist...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:29 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
postgres is a little unique w/ table names and case sensitivity. check the docs and make sure the tables have the names that you and hibernate think they are .


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:38 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Thats not it. I checked, everything matches.

Thanks though.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 2:50 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
FIXED!!!!

Dennis, you led me in the right direction w/ case sensitivity!

I forced everything to small i.e. ChangeCase became changecase ... ChangeCaseId became changecaseid.

This worked! I think what happened was, something somewhere got refreshed :)

I will change it back to the original schema in the morning.


Thank you everyone for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:29 pm 
Newbie

Joined: Mon Aug 30, 2004 1:37 am
Posts: 16
You may already know this - but to keep the schema/table/column names case sensitive you need to enclose them in double quotes in postgresql. To achieve this in the hibernate mapping file use ticks around the table and column names:
table name mapping:
Code:
table="`ChangeCase`"

column name mapping:
Code:
column="`ChangeCaseId`"

and the only way I could find to get the schema to work was to escape the quotes:
Code:
schema="&quot;YourSchemaName&quot;"

I hope this helps.
Grainne.


Top
 Profile  
 
 Post subject: Re: SQLGrammarException using PostgreSQL 8.0.4
PostPosted: Tue Sep 29, 2009 6:10 pm 
Newbie

Joined: Tue Sep 29, 2009 6:04 pm
Posts: 2
Despues de muchas vueltas, con postgres me funciono esto...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="zavaleta.luis.VO">
<class name="CatTiendasVO" table="&quot;CatTiendas&quot;">
<id name="idTienda" column="&quot;idTienda&quot;">
<generator class="native"/>
</id>
<property name="idCadena" type="string" column="&quot;idCadena&quot;"/>

despues de esto solo siguen mas atributos con la misma nomeclatura y cerrar los tags... es una solucion fea, pero bueno... espero alguien tenga algo mejor XD..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.