-->
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.  [ 2 posts ] 
Author Message
 Post subject: Display Query not working?
PostPosted: Mon Apr 21, 2008 4:06 pm 
Newbie

Joined: Sun Apr 20, 2008 6:57 pm
Posts: 1
Experts,

I am doing this in NETBEANS ,ORACLE
I have created bean with fields id and name.
I have created a Facade file that is for session.My facade file is listed below.
My table is create table TEST (id varchar2(255) not null, name varchar2(255), primary key (id));

Problem is table gets created but when I try to see that data in netbeans console it doesnt work.

My question is How can I view the table data in netbeans console window?
Can someone suggest me on this.

My Facade file:-
Code:

public class TestFacade {
    public void saveTest(Test test) {
        Session session = hibdemo.TestHibernateUtil.currentSession();
        Transaction tx = session.beginTransaction();
        session.save(test);
        tx.commit();
        hibdemo.TestHibernateUtil.closeSession();
    }   
public void generate()
{
    Test test = new Test();
    test.setId("AA");
    test.setName("Tom");
    test.setAge(15);
    saveTest(test);

    test  = new Test();
    test.setId("BB");
    test.setName("Hary");
    test.setAge(16);
    saveTest(test);
}

  public void query()
    {
        Session querySession =   
         hibdemo.TestHibernateUtil.getSessionFactory().openSession();
        Transaction tx = querySession.beginTransaction();
        hibdemo.TestHibernateUtil.closeSession();
       
        Query query = querySession.createQuery("select hibdemo.name
         from Test hibdemo");
        for(Iterator itr=query.iterate();itr.hasNext();){
          Object[] row = (Object[]) itr.next();
          System.out.println("ID is : " + row[1]);
    }
        tx.commit();
 
        querySession.close();
       
    }

}


David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 21, 2008 9:47 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
why do you close the session after begin transaction in query?


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