Net sf hibernate QueryException: unexpected token

PessoALL

Estou usando o Hibernate. Para fazer inser está tudo ok.
Mas para fazer um select está dando o seguinte erro:

net.sf.hibernate.QueryException: unexpected token: in [ SELECT C01TCL from C01TCL in class cockpitptb.hibernate.C01TCL where C01TCL.AF01CL=:name]
at net.sf.hibernate.hql.FromParser.token(FromParser.java:89)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1517)
at cockpitptb.FindC01TCLByAF01CL.main(FindC01TCLByAF01CL.java:47)
Exception in thread “main”

meu arquivo arquivo C01TCL.hbm.xml é o seguinte:

<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE hibernate-mapping
PUBLIC “-//Hibernate/Hibernate Mapping DTD//EN”
http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd”>

<hibernate-mapping>

&lt;class name="cockpitptb.hibernate.C01TCL" table="C01TCL"&gt;

    &lt;!-- A 32 hex character is our surrogate key. It's automatically
        generated by Hibernate with the UUID pattern. --&gt;
    &lt;id name="PF01ID" type="string" unsaved-value="null" &gt;
        &lt;column name="PF01ID" sql-type="char(32)" not-null="true"/&gt;
        &lt;generator class="uuid.hex"/&gt;
    &lt;/id&gt;
	
	&lt;property name="AF01CL"&gt;
		&lt;column name="AF01CL" sql-type="char(2)" not-null="true"/&gt;
	&lt;/property&gt;
	
 
&lt;/class&gt;

O erro aconte na seguinte classe:

public class FindC01TCLByAF01CL {
public static void main(String[] args) throws Exception {
// query to issue
String query = " "
// + "SELECT c.AF01CL from C01TCL as c "
+ "SELECT C01TCL from C01TCL "
+ "in class cockpitptb.hibernate.C01TCL "
//+ “where lower(C01TCL.AF01CL)=lower(:name)”;
//+ “where c.AF01CL=:name”;
+ “where C01TCL.AF01CL=:name”;

    // search for what?
    String name = "01";

    // init
    Configuration cfg = new Configuration().addClass(C01TCL.class);

    SessionFactory sf = cfg.buildSessionFactory();

    // open session
    Session sess = sf.openSession();

    // search and return
    List list = sess.find(query, name, Hibernate.STRING);

    if (list.size() == 0) {
        System.out.println("No mercados named " + name);
        System.exit(0);
    }
    System.out.println("list.size()=" + list.size());
    C01TCL c01tcl = (C01TCL) list.get(0);
    sess.close();
    System.out.println("Found mercado: " + c01tcl);
}

}

Depois de muito pesquisar no google recorri a vocês, por isso toda ajuda é bem vinda.

Obrigado

String query = &quot;SELECT c from C01TCL as c &quot;+ &quot;WHERE c.AF01CL=&#58;name&quot;;

Utilize essa query.

:wink:

Volnei

ontem cheguei a fazer:

String query = &quot;SELECT C01TCL  from C01TCL as c &quot;+
                         &quot;WHERE c.AF01CL=&#58;name&quot;;

Mas ocorria um erro no momento do cast:

 C01TCL c01tcl = &#40;C01TCL&#41; list.get&#40;0&#41;; 

Agora conforme vc falou:

String query = &quot;SELECT c from C01TCL as c &quot;+
                         &quot;WHERE c.AF01CL=&#58;name&quot;;

Agora, deu tudo certo.

Muito obrigado pela ajuda.
Obrigadão