Boa tarde pessoal! Estou com um problema na minha aplicação desktop. Uso o hibernate e o banco é o mySQL 5.
O erro é o seguinte:
org.hibernate.QueryException: could not resolve property: idCurso of: dominio.Turma [SELECT p FROM dominio.Turma p where p.idCurso = '2']
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1362)
at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:279)
at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:386)
at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:566)
at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:241)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:188)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:727)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1216)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3525)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
e mais um monte de linha dando seqüência nisto ai.
Acontece que pelo que analisei está tudo certo:
Turma.java
public class Turma implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private int idTurma;
private Curso curso;
private String nome;
private String turno;
private Set<Matricula> matriculas = new HashSet<Matricula>(0);
private Set<Matricula> matriculas_1 = new HashSet<Matricula>(0);
private Set<Ministra> ministras = new HashSet<Ministra>(0);
private Set<Ministra> ministras_1 = new HashSet<Ministra>(0);
private static final HibernateRepositorio hibernateRepositorio = new HibernateRepositorio();
public Turma() {
}
public Turma(Curso curso, String nome, String turno) {
this.curso = curso;
this.nome = nome;
this.turno = turno;
}
public Turma(Curso curso, String nome, String turno,
Set<Matricula> matriculas, Set<Matricula> matriculas_1,
Set<Ministra> ministras, Set<Ministra> ministras_1) {
this.curso = curso;
this.nome = nome;
this.turno = turno;
this.matriculas = matriculas;
this.matriculas_1 = matriculas_1;
this.ministras = ministras;
this.ministras_1 = ministras_1;
}
//GETTERS AND SETTERS
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 10/11/2008 00:07:15 by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
<class name="dominio.Turma" table="turma" catalog="alagoascursos">
<id name="idTurma" type="java.lang.Integer">
<column name="id_turma" />
<generator class="identity" />
</id>
<many-to-one name="curso" class="dominio.Curso" fetch="select">
<column name="id_curso" not-null="true" />
</many-to-one>
<property name="nome" type="string">
<column name="nome" length="45" not-null="true" />
</property>
<property name="turno" type="string">
<column name="turno" length="45" not-null="true" />
</property>
<set name="matriculas" inverse="true">
<key>
<column name="id_turma" not-null="true" />
</key>
<one-to-many class="dominio.Matricula" />
</set>
<set name="matriculas_1" inverse="true">
<key>
<column name="id_turma" not-null="true" />
</key>
<one-to-many class="dominio.Matricula" />
</set>
<set name="ministras" inverse="true">
<key>
<column name="id_turma" not-null="true" />
</key>
<one-to-many class="dominio.Ministra" />
</set>
<set name="ministras_1" inverse="true">
<key>
<column name="id_turma" not-null="true" />
</key>
<one-to-many class="dominio.Ministra" />
</set>
</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>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/########</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">######</property>
<property name="hibernate.connection.password">######</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- session mapping -->
<mapping resource="Aluno.hbm.xml" />
<mapping resource="Aula.hbm.xml" />
<mapping resource="Banco.hbm.xml" />
<mapping resource="Boleto.hbm.xml" />
<mapping resource="Cartao.hbm.xml" />
<mapping resource="Cheque.hbm.xml" />
<mapping resource="ControleCheque.hbm.xml" />
<mapping resource="Curso.hbm.xml" />
<mapping resource="Materia.hbm.xml" />
<mapping resource="Matricula.hbm.xml" />
<mapping resource="Ministra.hbm.xml" />
<mapping resource="Modulo.hbm.xml" />
<mapping resource="OrgaoExpedidor.hbm.xml" />
<mapping resource="PagarAula.hbm.xml" />
<mapping resource="PagarAulaCheque.hbm.xml" />
<mapping resource="PagarMatricula.hbm.xml" />
<mapping resource="Professor.hbm.xml" />
<mapping resource="Turma.hbm.xml" />
<mapping resource="Usuario.hbm.xml" />
</session-factory>
</hibernate-configuration>
public ArrayList<Object> consultarPor(Object objeto, String atributo, Object campo) throws HibernateException {
ArrayList<Object> listaObjetos = new ArrayList<Object>();
try {
session = HibernateUtil.currentSession();
Query query = session.createQuery("SELECT p FROM " + objeto.getClass().getName() + " p where p." + atributo + " = '" + campo + "'");
for(Iterator it=query.iterate();it.hasNext();){
listaObjetos.add(it.next());
}
} catch (Exception e) {
session.cancelQuery();
e.printStackTrace();
} finally {
HibernateUtil.sessionClose();
}
return listaObjetos;
}
Alguém poderia desvendar este mistério? :?