Problema hibernate

7 respostas
joaosavio
org.hibernate.QueryException: could not resolve property: login of: vo.UsuarioVO [from vo.UsuarioVO as user where user.login = 'adm']
        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:1358)
        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:728)
        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)

...
<?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.cglib.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/cadastro</property>
        <property name="hibernate.connection.username">postgres</property>        
        <property name="hibernate.connection.password">123456</property>         
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="show_sql">true</property>
        <property name="hibernate.generate_statistics">true</property>
        <property name="hibernate.use_sql_comments">true</property>        
        <mapping class="vo.UsuarioVO"/>
       
    </session-factory>
</hibernate-configuration>
package vo;

/**
 *
 * @author joaosavio
 */
import javax.persistence.*;

@Entity
public class UsuarioVO implements java.io.Serializable {
    @Id
    @GeneratedValue
    private int id;
    private String usuario;
    private String senha;

    public int getId() {
        return id;
    }

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

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

}
public UsuarioVO checarLogin(String login) throws HibernateException 
    {
        try 
        {
            DAOFactory dao = new DAOFactory();
            dao.beginTransaction();
            String hql = "from UsuarioVO as user where user.login = '"+login+"'";
            session = HibernateUtil.getSession();
            Query q = session.createQuery(hql);
            usuarioVO = (UsuarioVO) q.uniqueResult();
            dao.commit();
            dao.close();
            return usuarioVO;
        }
        catch (Exception e) 
        {
            e.printStackTrace();
            return null;
        }
    }

no bd existe a tabela usuarios que tem tres colunas: id, usuario e senha

da esse erro quando roda esse procedimento

Espero que possam ajudar

abraços

7 Respostas

jmoreira
...
# org.hibernate.QueryException: could not resolve property: login of: vo.UsuarioVO [from vo.UsuarioVO as user where user.login= 'adm']  
#         at
...

A exceção é bem clara. O atributo login NAO existe na sua classe UsuarioVO. O problema está aqui:

... 
String hql = "from UsuarioVO as user where user.login= '"+login+"'";  
...

Faça assim:

String hql = "from UsuarioVO as user where user.usuario= '"+login+"'"; [/quote]

joaosavio

valeu cara

mas agora ta dando outro erro

Hibernate: /* from UsuarioVO as user where user.usuario= 'adm' */ select usuariovo0_.id as id0_, usuariovo0_.senha as senha0_, usuariovo0_.usuario as usuario0_ from UsuarioVO usuariovo0_ where usuariovo0_.usuario='adm'
WARN  30-03 10:27:37,171 (JDBCExceptionReporter.java:logExceptions:77)  -SQL Error: 0, SQLState: 42P01
ERROR 30-03 10:27:37,171 (JDBCExceptionReporter.java:logExceptions:78)  -ERROR: relation "usuariovo" does not exist
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)

eu acho que deve ser no mapeamento

joaosavio

up

joaosavio

alguem?

jmoreira
# WARN  30-03 10:27:37,171 (JDBCExceptionReporter.java:logExceptions:77)  -SQL Error: 0, SQLState: 42P01  
# ERROR 30-03 10:27:37,171 (JDBCExceptionReporter.java:logExceptions:78)  -ERROR: relation "usuariovo" does not exist

Cara, primeiro parece que houve uma exceção do BD (SQL Error: 0, SQLState: 42P01) e Depois o Hibernate reclamou de uma relação(ERROR: relation “usuariovo” does not exist) que não existe.

Verifique onde você colocou a String “usuariovo” e veja se ela está fazendo sentido onde está aparecendo. Depois se não der certo, verifique como está o mapeamento da classe UsuarioVO com relação aohibernate.cfg.xml.. Qualquer coisa, post ai o relacionamento para darmos uma olhada.

Se você for “marinheiro de primeira viagem” com o hibernate… cuidado! A “surra” poderá ser violenta. Estilo BOPE. :lol: :smiley:

joaosavio

fala cara

no meu banco de dados chamado cadastro so estou usando uma tabela (usuarios) que tem 3 campos: id, usuario, senha

eu mapeie assim:

pois a classe UsuarioVO esta dentro do pacote VO

<?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.cglib.use_reflection_optimizer">false</property>  
         <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>  
         <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/cadastro</property>  
         <property name="hibernate.connection.username">postgres</property>          
         <property name="hibernate.connection.password">123456</property>           
         <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>  
         <property name="show_sql">true</property>  
         <property name="hibernate.generate_statistics">true</property>  
         <property name="hibernate.use_sql_comments">true</property>          
         <mapping class="vo.UsuarioVO"/>  
          
     </session-factory>  
 </hibernate-configuration>

correto?

abraços e valeu

joaosavio

resolvido

valeu pessoal

Criado 30 de março de 2008
Ultima resposta 31 de mar. de 2008
Respostas 7
Participantes 2