-->
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.  [ 3 posts ] 
Author Message
 Post subject: SQLGrammarException problem
PostPosted: Sun May 06, 2007 9:18 am 
Newbie

Joined: Sun Jun 20, 2004 7:41 am
Posts: 7
Hello,

I've got a nasty problem as described below. The comma character appended to the generated SQL seems to be the cause (update document, set ever_posted=? where doc_kind='A' and login=? and main_doc_id=?
). Anybody knows how to cope with this?

Regards
Chris

Hibernate version:
3.2.3.ga

Mapping documents:
<?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
>
<class
name="pl.addcom.df.Document"
table="document"
>

<id
name="id"
column="id"
type="java.lang.Integer"
access="field"
>
<generator class="sequence">
<param name="sequence">document_seq</param>
</generator>
</id>

<discriminator
column="doc_kind"
not-null="true"
type="java.lang.String"
length="2"
/>

<version
name="version"
column="version"
type="java.lang.Integer"
access="field"
unsaved-value="null"
/>

<property
name="content"
type="java.lang.String"
update="true"
insert="true"
column="content"
length="1024"
not-null="true"
/>

<property
name="title"
type="java.lang.String"
update="true"
insert="true"
column="title"
length="128"
not-null="true"
/>

<property
name="comments"
type="java.lang.String"
update="true"
insert="true"
column="comments"
length="512"
not-null="false"
/>

<property
name="regDate"
type="java.sql.Date"
update="true"
insert="true"
column="reg_date"
not-null="true"
/>

<many-to-one
name="documentType"
class="pl.addcom.df.DDocumentType"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="d_doc_type_id"
not-null="true"
/>

<many-to-one
name="documentStatus"
class="pl.addcom.df.DDocumentStatus"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="d_doc_stat_id"
not-null="true"
/>

<many-to-one
name="author"
class="pl.addcom.df.Employee"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="author_id"
not-null="true"
/>

<many-to-one
name="owner"
class="pl.addcom.df.Employee"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="owner_id"
not-null="true"
/>

<property
name="ownershipStartTime"
type="java.sql.Timestamp"
update="true"
insert="true"
access="field"
column="ownership_start"
not-null="true"
/>

<set
name="attachments"
table="attachment"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
access="field"
>

<key
column="document_id"
>
</key>

<one-to-many
class="pl.addcom.df.Attachment"
/>

</set>

<set
name="documentChanges"
table="document_hist"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
access="field"
>

<key
column="document_id"
>
</key>

<one-to-many
class="pl.addcom.df.DocumentHistory"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Document.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="pl.addcom.df.MainDocument"
discriminator-value="M"
>
<property
name="archived"
type="java.lang.Boolean"
update="true"
insert="true"
column="archived"
/>

<property
name="docDate"
type="java.sql.Date"
update="true"
insert="true"
column="doc_date"
not-null="false"
/>

<property
name="endDate"
type="java.sql.Date"
update="true"
insert="true"
column="end_date"
not-null="false"
/>

<property
name="origSymbol"
type="java.lang.String"
update="true"
insert="true"
column="orig_symbol"
length="32"
not-null="false"
/>

<property
name="segreg"
type="java.lang.String"
update="true"
insert="true"
column="segreg"
length="16"
not-null="false"
/>

<property
name="urgent"
type="java.lang.Boolean"
update="true"
insert="true"
column="urgent"
not-null="false"
/>

<property
name="urgentReason"
type="java.lang.String"
update="true"
insert="true"
column="urgent_reason"
length="128"
not-null="false"
/>

<set
name="associatedDocuments"
table="document"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
access="field"
>

<key
column="main_doc_id"
>
</key>

<one-to-many
class="pl.addcom.df.AssociatedDocument"
/>

</set>

<many-to-one
name="customer"
class="pl.addcom.df.Customer"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="customer_id"
not-null="false"
/>

<many-to-one
name="registry"
class="pl.addcom.df.DRegistry"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="d_registry_id"
not-null="false"
/>

<many-to-one
name="unifiedDocRegistry"
class="pl.addcom.df.DUnifiedDocRegistry"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="d_udoc_reg_id"
not-null="false"
/>

<many-to-one
name="unit"
class="pl.addcom.df.DUnit"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="unit_id"
not-null="false"
/>

<set
name="documentTracks"
table="document_tracks"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
access="field"
>

<key
column="document_id"
>
</key>

<one-to-many
class="pl.addcom.df.DocumentTrackRecord"
/>

</set>

<set
name="documentStatusChanges"
table="doc_stat_change"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
access="field"
>

<key
column="document_id"
>
</key>

<one-to-many
class="pl.addcom.df.DocumentStatusChangeRecord"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-MainDocument.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>
<subclass
name="pl.addcom.df.AssociatedDocument"
discriminator-value="A"
>

<many-to-one
name="mainDocument"
class="pl.addcom.df.MainDocument"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="field"
column="main_doc_id"
not-null="false"
/>

<property
name="everPosted"
type="java.lang.Boolean"
update="true"
insert="true"
column="ever_posted"
not-null="false"
/>

<property
name="closeDate"
type="java.sql.Date"
update="true"
insert="true"
column="close_date"
not-null="false"
/>

<property
name="createDate"
type="java.sql.Date"
update="true"
insert="true"
column="create_date"
not-null="false"
/>

<set
name="externalContents"
table="external_content"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
access="field"
>

<key
column="assoc_doc_id"
>
</key>

<one-to-many
class="pl.addcom.df.ExternalContent"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-AssociatedDocument.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>

</class>

</hibernate-mapping>

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

public void setAssociatedDocumentsAsPosted(MainDocument document, String owner) {
HibernateUtils.currentSession()
.createQuery(new StringBuffer(
"update pl.addcom.df.AssociatedDocument ad ")
.append("set ad.everPosted = :everPosted ")
.append("where ad.owner.login = :owner and ")
.append("ad.mainDocument = :mainDocument ")
.toString())
.setBoolean("everPosted", Boolean.TRUE)
.setString("owner", owner)
.setEntity("mainDocument", document)
.executeUpdate();
}

Full stack trace of any exception that occurs:
Hibernate: update document, set ever_posted=? where doc_kind='A' and login=? and main_doc_id=?
13:34:33,093 ERROR [JDBCExceptionReporter] DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: ,;update document;<space>
13:34:33,093 ERROR [JDBCExceptionReporter] DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098, SQLERRMC: 2;-104;42601;,|update document|<space>
13:34:33,093 ERROR [JDBCExceptionReporter] DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098, SQLERRMC: 2;-104;42601;,|update document|<space>
13:34:33,109 ERROR [UniversalExceptionHandler] exception handled for user: hicnar
pl.addcom.df.BusinessLogicException: Hibernate related problem occured.
at pl.addcom.dfu.core.DFULocalBusinessLogicController.forwardDocument(DFULocalBusinessLogicController.java:251)
at pl.addcom.dfu.struts.action.ForwardDocument.execute(ForwardDocument.java:61)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at pl.addcom.df.utils.hibernate.HibernateFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at pl.addcom.df.utils.EncodingFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at pl.addcom.df.dao.AssociatedDocumentDAO.setAssociatedDocumentsAsPosted(Unknown Source)
at pl.addcom.dfu.core.DFULocalBusinessLogicController.forwardDocument(DFULocalBusinessLogicController.java:230)
... 28 more
Caused by: com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: ,;update document;<space>
at com.ibm.db2.jcc.a.hd.e(hd.java:1659)
at com.ibm.db2.jcc.a.hd.a(hd.java:1235)
at com.ibm.db2.jcc.c.jb.h(jb.java:149)
at com.ibm.db2.jcc.c.jb.a(jb.java:43)
at com.ibm.db2.jcc.c.w.a(w.java:30)
at com.ibm.db2.jcc.c.cc.g(cc.java:160)
at com.ibm.db2.jcc.a.hd.n(hd.java:1215)
at com.ibm.db2.jcc.a.id.gb(id.java:1780)
at com.ibm.db2.jcc.a.id.d(id.java:2255)
at com.ibm.db2.jcc.a.id.Y(id.java:537)
at com.ibm.db2.jcc.a.id.executeUpdate(id.java:520)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 34 more

Name and version of the database you are using:
DB2 8.2 express C

The generated SQL (show_sql=true):

update document, set ever_posted=? where doc_kind='A' and login=? and main_doc_id=?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 8:20 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Can we see you hibernate.cfg.xml file? By the way, code tags are your friend, makes life much easier on my eyes. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 2:07 pm 
Newbie

Joined: Sun Jun 20, 2004 7:41 am
Posts: 7
Hi,

Sory about not using the code tag. I managed to solve the problem with the following...

Code:
   public void setAssociatedDocumentsAsPosted(MainDocument document,
         String ownerLogin) {
       HibernateUtils.currentSession()
         .createQuery(new StringBuffer(
            "update pl.addcom.df.AssociatedDocument ad ")
               .append("set ad.everPosted = :everPosted ")
               .append("where ad.owner = ( from pl.addcom.df.Employee ")
               .append("where e.login = :ownerLogin) and ")
               .append("ad.mainDocument = :mainDocument ")         
               .toString())
            .setBoolean("everPosted", Boolean.TRUE)
            .setString("ownerLogin", ownerLogin)
            .setEntity("mainDocument", document)
            .executeUpdate();
   }


The SQL generated by the original code was not ok since there's no login property in the document (I mean the comma was not the only issue there). However... the AssociatedDocument -> Employee (owner) association is one point association and is of course navigable from the AssociatedDocument to Employee (It actually is defined in the Document class which is the superclass for AssociatedDocument) so I think the original code (expecially the following HQL "where ad.owner.login = :owner and") should produce correct SQL and work anyway.

The hibernate.cfg.xml is as follows (if it ever helps you :) )

Code:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- properties -->
        <property name="hibernate.connection.driver_class">
               com.ibm.db2.jcc.DB2Driver
        </property>
        <property name="hibernate.connection.url">
             jdbc:db2:TEST
        </property>
        <property name="hibernate.connection.username">username</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.dialect">
            org.hibernate.dialect.DB2Dialect
        </property>
        <property name="hibernate.connection.pool_size">4</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
      <property name="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml</property>
      <property name="hibernate.cache.use_query_cache">true</property>

        <!-- mapping files -->
        <mapping resource="pl/addcom/df/Attachment.hbm.xml"/>
        <mapping resource="pl/addcom/df/AttachmentHistory.hbm.xml"/>
        <mapping resource="pl/addcom/df/Customer.hbm.xml"/>
        <mapping resource="pl/addcom/df/CustomerHistory.hbm.xml"/>
        <mapping resource="pl/addcom/df/DFileServer.hbm.xml"/>
        <mapping resource="pl/addcom/df/DDocumentStatus.hbm.xml"/>
        <mapping resource="pl/addcom/df/DDocumentType.hbm.xml"/>
        <mapping resource="pl/addcom/df/DEmployeeStatus.hbm.xml"/>
        <mapping resource="pl/addcom/df/DLanguage.hbm.xml"/>
        <mapping resource="pl/addcom/df/DPhone.hbm.xml"/>
        <mapping resource="pl/addcom/df/DPosition.hbm.xml"/>
        <mapping resource="pl/addcom/df/DRegistry.hbm.xml"/>
        <mapping resource="pl/addcom/df/DRoom.hbm.xml"/>
        <mapping resource="pl/addcom/df/DUnifiedDocRegistry.hbm.xml"/>
        <mapping resource="pl/addcom/df/DUnit.hbm.xml"/>
        <mapping resource="pl/addcom/df/DocumentTrackRecord.hbm.xml"/>
        <mapping resource="pl/addcom/df/DocumentStatusChangeRecord.hbm.xml"/>
        <mapping resource="pl/addcom/df/Document.hbm.xml"/>
        <mapping resource="pl/addcom/df/DocumentHistory.hbm.xml"/>
        <mapping resource="pl/addcom/df/Employee.hbm.xml"/>
        <mapping resource="pl/addcom/df/Absence.hbm.xml"/>
       <mapping resource="pl/addcom/df/EmployeeToLanguage.hbm.xml"/>
       <mapping resource="pl/addcom/df/EmployeeToDUnit.hbm.xml"/>
       <mapping resource="pl/addcom/df/EmployeeEntryToDPhone.hbm.xml"/>
       <mapping resource="pl/addcom/df/EmployeeEntryToDRoom.hbm.xml"/>
        <mapping resource="pl/addcom/df/EmployeeEntry.hbm.xml"/>
        <mapping resource="pl/addcom/df/CustomerLoginRecord.hbm.xml"/>
        <mapping resource="pl/addcom/df/EmployeeLoginRecord.hbm.xml"/>
        <mapping resource="pl/addcom/df/ExternalContent.hbm.xml"/>
        <mapping resource="pl/addcom/df/Message.hbm.xml"/>
        <mapping resource="pl/addcom/df/Permissions.hbm.xml"/>
        <mapping resource="pl/addcom/df/DStructureNode.hbm.xml"/>
    </session-factory>
</hibernate-configuration>



Regards
Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.