-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Problem with query (again)
PostPosted: Wed Aug 25, 2004 5:15 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
2.1.3:

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

<hibernate-mapping>
<class name = "escola.Utilizador" table = "utilizadores">
<id name = "id" column = "id" unsaved-value = "null">
<generator class = "increment" />
</id>
<many-to-one
name = "relatorio"
column = "rel_relatorios"
class = "escola.Relatorio"
cascade = "all">
</many-to-one>
<many-to-one
name = "acessorios"
column = "rel_acessorios"
class = "escola.Acessorios"
cascade = "all">
</many-to-one>
<property name = "nomeUtilizador" column = "nomeUtilizador" />
<property name = "nomeCompleto" column = "nomeCompleto" />
<property name = "palavraPasse" column = "palavraPasse" />
<property name = "perfil" column = "perfil" />
</class>
</hibernate-mapping>


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

<hibernate-mapping>
<class name = "escola.Acessorios" table = "acessorios">
<id name = "id" column = "id" unsaved-value = "null">
<generator class = "increment" />
</id>
<property name = "epocaActual" column = "epocaActual" />
</class>
</hibernate-mapping>

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="hibernate.show_sql">false</property>
<!-- mapping files -->
<mapping resource = "escola/Relatorio.hbm.xml"/>
<mapping resource = "escola/Turma.hbm.xml"/>
<mapping resource = "escola/Acessorios.hbm.xml"/>
<mapping resource = "escola/EducacaoArtistica.hbm.xml"/>
<mapping resource = "escola/EducacaoFisica.hbm.xml"/>
<mapping resource = "escola/EducacaoMoralEReligiosa.hbm.xml"/>
<mapping resource = "escola/EducacaoMusical.hbm.xml"/>
<mapping resource = "escola/Matematica.hbm.xml"/>
<mapping resource = "escola/LinguaPortuguesa.hbm.xml"/>
<mapping resource = "escola/LEI.hbm.xml"/>
<mapping resource = "escola/Q9.hbm.xml"/>
<mapping resource = "escola/Q10.hbm.xml"/>
<mapping resource = "escola/Q12.hbm.xml"/>
<mapping resource = "escola/Q17.hbm.xml"/>
<mapping resource = "escola/Q19.hbm.xml"/>
<mapping resource = "escola/Q22Al.hbm.xml"/>
<mapping resource = "escola/Q22Disc.hbm.xml"/>
<mapping resource = "escola/Q22EE.hbm.xml"/>
<mapping resource = "escola/Q22Esc.hbm.xml"/>
<mapping resource = "escola/Q23.hbm.xml"/>
<mapping resource = "escola/Q34.hbm.xml"/>
<mapping resource = "escola/Utilizador.hbm.xml"/>
</session-factory>
</hibernate-configuration>
:


Session sess = Utilitarios.currentSession();

String s = "select a from Acessorios as a";
List l = sess.find(s);
a = (Acessorios) l.get(0);
int epocaActual = a.getEpocaActual();
System.out.println(epocaActual);

String nomeUtilizador = login.jTextFieldnome.getText();
String palavraPasse = login.jTextFieldPp.getText();

String query = "SELECT ut from Utilizador as ut "
+ "WHERE ut.palavraPasse = :palavraPasse "
+ "AND ut.nomeUtilizador = :nomeUtilizador "
+ "AND ut.relatorios.turma.q1 = :epocaActual";

Query q = sess.createQuery(query);
q.setString("palavraPasse", palavraPasse);
q.setString("nomeUtilizador", nomeUtilizador);
q.setInteger("epocaActual", epocaActual);
List lista = q.list();

if (lista.size() > 0) {
ut = (Utilizador) lista.get(0);
System.out.println("yes");
System.out.println("id = " + ut.getId());
return (Utilizador) lista.get(0);
}
else {
System.out.println("no");
return null;
}
}:


net.sf.hibernate.QueryException: could not resolve property: relatorios of: escola.Utilizador [SELECT ut from escola.Utilizador as ut WHERE ut.palavraPasse = :palavraPasse AND ut.nomeUtilizador = :nomeUtilizador AND ut.relatorios.turma.q1 = :epocaActual]
at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:249)
at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:123)
at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:334)
at net.sf.hibernate.hql.WhereParser.doToken(WhereParser.java:366)
at net.sf.hibernate.hql.WhereParser.token(WhereParser.java:251)
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:293)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1554)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1525)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at escola.Porteiro.getUtilizador(Porteiro.java:38)
at escola.FrameLogin.jButtonEntrar_actionPerformed(FrameLogin.java:68)
at escola.FrameLogin_jButtonEntrar_actionAdapter.actionPerformed(FrameLogin.java:85)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
:


MySql 4.0.12-nt:

Debug level Hibernate log excerpt:


When i make this:

Code:
        String s = "select  a from Acessorios as a";
        List l = sess.find(s);
        a = (Acessorios) l.get(0);
        int epocaActual = a.getEpocaActual();
System.out.println(epocaActual);

i can get an int: 2004;
but the problem appears when i try to run the second query:
Code:
        String nomeUtilizador = login.jTextFieldnome.getText();
        String palavraPasse = login.jTextFieldPp.getText();
       
        String query = "SELECT ut from Utilizador as ut "
            + "WHERE ut.palavraPasse = :palavraPasse "
            + "AND ut.nomeUtilizador = :nomeUtilizador "
            + "AND ut.relatorios.turma.q1 = :epocaActual";

        Query q = sess.createQuery(query);
        q.setString("palavraPasse", palavraPasse);
        q.setString("nomeUtilizador", nomeUtilizador);
        q.setInteger("epocaActual", epocaActual);
        List lista = q.list();


What am i doing wrong?
thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 6:16 pm 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
I think you type
Quote:
ut.relatorios...
and it should be
Quote:
ut.relatorio
(no 's').


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 6:20 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
CASE SOLVED:
in the query wasnt "relatorios" but "relatorio"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 6:21 pm 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
I think you type
Quote:
ut.relatorios

and it should be
Quote:
ut.relatorio

(no 's').


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 6:21 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
croudet wrote:
I think you type
Quote:
ut.relatorios...
and it should be
Quote:
ut.relatorio
(no 's').

thanks, that's it


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.