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;
}