onaled777
asked on
Preventing Cast Exception
The code below throws an error at the line:
owner = (Owner) session.load(Owner.class, new Long(id));
whenever an int value is passed to the getOwner method.
How do I modify this method to accept both int and long primitives in the method.
owner = (Owner) session.load(Owner.class, new Long(id));
whenever an int value is passed to the getOwner method.
How do I modify this method to accept both int and long primitives in the method.
public static Owner getOwner(long id)
{
Owner owner = null;
if (id > 0)
{
PersistorSession session = null;
try
{
session = PersistorSessionFactory.getInstance().getPersistorSession();
owner = (Owner) session.load(Owner.class, new Long(id));
}
catch (PersistenceException pe)
{
logger.error("Persistence error loading the following Owner object id from memory: " + id, pe);
pe.printStackTrace();
}
catch (Exception e)
{
logger.error("Error loading the following Owner object id from memory: " + id, e);
e.printStackTrace();
}
finally
{
if (session != null)
{
try
{
session.close();
session = null;
}
catch (PersistenceException pe)
{
logger.error("Error occured while closing persistor session", pe);
pe.printStackTrace();
}
}
}
}
return owner;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER