-->
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.  [ 10 posts ] 
Author Message
 Post subject: Performing the Load
PostPosted: Sun Jun 06, 2004 6:34 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
i'm very very new to hibernate 2.1.3,( MysSql 4.0.12 nt, winXP pro) and i can insert and load.
I want to display the several children for a certain father. So far so good, but what i get is something inside "[]".
How can i arrange things to get children without the "[]"?
Example:
I get [sete] instead of sete
thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 06, 2004 6:36 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
oops
and i forgot to say this: if i return, from load, several children, they appear all in one line, not in several like:
[one, two, seven],
instead of:
one
two
seven
etc


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 9:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
No idea what your talking about.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 3:43 am 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
here's what i mean:
imagine parentA has several children: childA1, childA2 and so on.
ParentB also has several children: childB1, childB2, childB3 and so on.
What i want is: if i make a load of parentA's children, they show up like this:
childA1
childA2
childA3
and so on
But what i'm getting is:
[childA1, childA2, childA3]
with "[]" and commas too....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 3:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
select elements(parent.childs) from Parent parent

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 5:19 am 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
thanks a lot for your answer!
my relevant java code:
Code:
public void setTudo() throws HibernateException {

        //String s = (String) visual.lstTurmas.getSelectedValue();
        SessionFactory sf = new Configuration().configure().buildSessionFactory();

        Session sess = HibernateUtil.currentSession();
        Transaction t = sess.beginTransaction();

        LeLista ll = new LeLista();
        int oano = ll.oAno( (String) visual.lstTurmas.getSelectedValue());
        String aturma = ll.aTurma( (String) visual.lstTurmas.getSelectedValue());
        aturma = "" + "'" + aturma + "'";
        /*String query =
            "select rel from Relatorio as rel where rel.turma.ano = " + oano +
            " AND turma = " + aturma;*/
          String query =  "select elements(rel.turma.detalhe) from Relatorio as rel where rel.turma.ano = " + oano +
            " AND turma = " + aturma;
        List lista = sess.find(query);

        rel =  (Relatorio) lista.get(0);//    ERROR HERE!!!

        // ...

        sess.saveOrUpdate(rel);

        t.commit();

        HibernateUtil.closeSession();

    }

on start up i get this error msg:
Quote:
java.lang.ClassCastException
at relatorio.Assistente.setTudo(Assistente.java:199)
at relatorio.VisualSwing.<init>(VisualSwing.java:114)
at relatorio.Visual.<init>(Visual.java:19)
at relatorio.Visual.main(Visual.java:50)


Can you help me please?
thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 5:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
the query returns a list of child, not the parent

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 6:45 am 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
Once again thanks for helping
Well, i got it without the "[]"
good!
but now i only get, in my JList, the first child...
i tried the older code - commented - and a new one inspired in what you told me
i wonder if its because of
Code:
lista1.get(0)

should i loop?

here's my relevant code:
Code:
         /*for (int i = 0; i < visual.lstDetalhe.getModel().getSize(); i++) {
            Detalhe detalhe = new Detalhe();
            visual.lstDetalhe.setSelectedIndex(i);
            String nova = visual.lstDetalhe.getSelectedValue().toString();
            detalhe.setEstrategia(nova);*/

    Detalhe detalhe = new Detalhe();    // adiciono ao Set
            rel.getTurma().adicionarDetalhe(detalhe);
            String query1 = "select elements(rel.turma.detalhe) from Relatorio as rel where rel.turma.ano = " +
                                   oano +
                                   " AND turma = " + aturma;
                   List lista1 = sess.find(query);
           
           
                   detalhe = (Detalhe) lista1.get(0);

        //}

Can you please help me once more?
thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 7:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
advice: read the doc

it returns the childs
so get(0) = 1rst child
get(1) = 2nd child....

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 8:18 am 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
that's what i did:
Code:
        String query = "select elements(rel.turma.detalhe) from Relatorio as rel where rel.turma.ano = " +
                       oano +
                       " AND turma = " + aturma;
        List lista = sess.find(query);
        for (int i = 0; i < lista.size(); i++) {
            detalhe = (Detalhe) lista.get(i);
            visual.info2.addElement(detalhe);
        }

and got it ok!

Thank you very much!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.