Olá,
mais uma duvida porque está dando erro qdo tento usar HQL
select com where não encontra o mapeamento da classe???
se alguém puder me ajudar agradeceria…
public List listasCategoria(int idcategoria) throws Exception {
Categoria categoria = new Categoria();
List objetos = new ArrayList();
try{
SessionFactory sf = new Configuration().configure("br/com/uso/model/hibernate.cfg.xml").buildSessionFactory();
Session s = sf.openSession();
Query select = s.createQuery("from categorias as cat where cat.idcategoria>:idcategoria");
select.setInteger("idcategoria", idcategoria);
objetos =select.list();
System.out.println(("resultado"+objetos));
//for (Iterator iterator = objetos.iterator(); iterator.hasNext();) {
// Categoria object = (Categoria) iterator.next();
// categoria=object;
//}
}catch(Exception e){
System.out.println("Erro"+e);
throw new Exception(e);
}
System.out.println("voltou");
return objetos;
}
----
Erroorg.hibernate.hql.ast.QuerySyntaxException: categorias is not mapped [from categorias as cat where cat.idcategoria>:idcategoria]
Exception in thread "main" java.lang.Exception: org.hibernate.hql.ast.QuerySyntaxException: categorias is not mapped [from categorias as cat where cat.idcategoria>:idcategoria]
at br.com.uso.model.GerenciadorCategoria.listasCategoria(GerenciadorCategoria.java:114)
at br.com.uso.model.TestaCategoria.main(TestaCategoria.java:33)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: categorias is not mapped [from categorias as cat where cat.idcategoria>:idcategoria]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at br.com.uso.model.GerenciadorCategoria.listasCategoria(GerenciadorCategoria.java:104)
... 1 more
----------------------------------
<?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>
<class name="br.com.uso.model.Categoria" table="categorias">
<id name="idcategoria" column="idcategoria" type="int">
<generator class="native"/>
</id>
<property name="categoria"/>
</class>
</hibernate-mapping>
-----
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!--Database connection setting -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1/loja</property>
<property name="connection.username">root</property>
<property name="connection.password">paribe</property>
<!--JDBC connection pool(use built-in)-->
<property name="connection.pool_size">1</property>
<!--SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all execute SQL to stdout-->
<property name="show_sql">false</property>
<mapping resource="br/com/uso/model/Categoria.hbm.xml"/>
</session-factory>
</hibernate-configuration>