-->
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.  [ 1 post ] 
Author Message
 Post subject: Session problem
PostPosted: Fri Aug 04, 2006 8:14 am 
Newbie

Joined: Fri Aug 04, 2006 7:57 am
Posts: 2
Location: Mumbai
hi,

Iam new to Hibernate and I have a small application which has ADD and LIST functionality.
Following are the environment:

Tapestry 4.0 [ for web development]
Hibernate 3 [ for mapping java classes to the oracle database]
Jdk 1.4
And Eclipse 3.1 [IDE]

My application is working fine but there is one single problem:

When I Add details for the first time it comes in the List page but if i add second or third time it won't come.I think it is related to sessions...please advice

following is the code for ADD:



Code:
public final boolean addResource(AceResource acr)
   {
      boolean status = false;
      try
      {
         int id = 0;
         System.out.println("OracleAgent called");
         Session session = getSession();
         //Session session_ = getSession();
         tran = session.beginTransaction();
         List result = session.createSQLQuery("select max(resource_id) from ace_resource").list();
         
         for (int i = 0; i < result.size(); i++)
         {
            id = Integer.parseInt(result.get(i).toString());
         }
            //tran.commit();
         //tran = session.beginTransaction();
         id = ++id;
         Date sysdate= new Date();
         acr.setId(id);
         acr.setCreate_date(sysdate);
         session.save(acr);
         //session.setFlushMode(FlushMode.AUTO);
         tran.commit();
         status = true;
         session.flush();
         session.close();
      }
      catch(Exception e)
      {
         System.out.print("Exception in OracleAgent.addCarriers()");
         e.printStackTrace(System.out);
         status = false;
         closeSession();         
      }



code for Listing :
Code:
public final Vector getResource()
   {
      if(formatter == null)
         formatter = new SimpleDateFormat("MMM dd, yyyy");
      
      Vector accResource = new Vector();
      Session session = getSession();
      AceResource obj = null;
      tran = session.beginTransaction();
      List result = session.createQuery("from AceResource order by resource_id desc").list();
      
      for(int i=0; i < result.size();i++)
      {
         obj = (AceResource)result.get(i);
         obj.setCreate_date_String(formatter.format(obj.getCreate_date()));
         accResource.addElement(obj);
      }
      
      tran.commit();
      
      return accResource;
   }

_________________
Liju Thomas


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

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.