[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3797) Incorrect SQL syntax for EJB query involving Entity with composite Key

Diego Palumbo (JIRA) noreply at atlassian.com
Wed Mar 4 05:19:38 EST 2009


Incorrect SQL syntax for EJB query involving Entity with composite Key
----------------------------------------------------------------------

                 Key: HHH-3797
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3797
             Project: Hibernate Core
          Issue Type: Bug
          Components: query-hql
         Environment: Hibernate JPA  (hibernate3.jar), Sql Server 2003 
            Reporter: Diego Palumbo


Hello. 
I have some trouble with queries on Entities with composite key as follow: 

select count(o) from Logqueryt as o

the key is LogquerytPK.java (see the follwing definition). 

Now i'm not able to see the SQL generated but when i try to excute my project i receive an SQLGrammarException (see follow report)

I also red this issue (http://opensource.atlassian.com/projects/hibernate/browse/HHH-2266)  where was considered the same problem  but I didn't hunderstand if this could be considered a bug or if I have to use a different syntax for this kind of queries. 

If it is a bug, was it fixed? 






  
------------------LogquerytPK--------------------------------------------------
package entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
 *
 * @author d.palumbo
 */
@Embeddable
public class LogquerytPK implements Serializable {
    @Basic(optional = false)
    @Column(name = "ID")
    private int id;
    @Basic(optional = false)
    @Column(name = "ANNO")
    private short anno;

    public LogquerytPK() {
    }

    public LogquerytPK(int id, short anno) {
        this.id = id;
        this.anno = anno;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public short getAnno() {
        return anno;
    }

    public void setAnno(short anno) {
        this.anno = anno;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) id;
        hash += (int) anno;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LogquerytPK)) {
            return false;
        }
        LogquerytPK other = (LogquerytPK) object;
        if (this.id != other.id) {
            return false;
        }
        if (this.anno != other.anno) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.LogquerytPK[id=" + id + ", anno=" + anno + "]";
    }

}
-------------------------------Exception-------------------------------------
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logWarnings
AVVERTENZA: SQL Warning: 170, SQLState: 37000
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logWarnings
AVVERTENZA: Preparing the statement failed: Line 1: Incorrect syntax near ','.
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logExceptions
AVVERTENZA: SQL Error: 170, SQLState: 37000
4-mar-2009 10.12.20 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Line 1: Incorrect syntax near ','.
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
        at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
        at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)
        at persistence.QueryTester.main(QueryTester.java:30)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.doList(Loader.java:2223)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
        at org.hibernate.loader.Loader.list(Loader.java:2099)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
        at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
        at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
        ... 1 more
Caused by: java.sql.SQLException: Line 1: Incorrect syntax near ','.
        at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
        at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
        at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
        at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
        at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
        at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
        at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
        at org.hibernate.loader.Loader.doQuery(Loader.java:674)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.doList(Loader.java:2220)
        ... 9 more
---------------------------------------------------------------------------

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list