The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Vijay.k (1) [Avatar] Offline
#1
I am using a Base class - 'AbstractDAO' that contains basic methods like 'insert(Object o),read(Class clazz,Long id),update(Object o),delete(Object o)' that take cares all the Exception handling . Now i have taken a 'StudentDAO' that extends 'AbstractDAO' and calls read method by passing 'Student' pojo class object. i.e below is the code in 'StudentDAO'
public Student getStudent(Long id) throws DataAccessLayerException {

return (Student) read(Student.class,id) ; // calling AbsractDAO - read( )

}
code in 'AbstractDAO'

protected Object read(Class clazz,Long id) {
Object obj = null ;
try{
startOperation() ;
obj = session.load(clazz,id);
tx.commit() ;
} catch (HibernateException e){
handleException(e);
} finally {
HibernateFactory.close(session);
}

return obj ;
}

But while trying to retrieve the (row)data from Database it is throwing an Exception saying "proxy could not be opened after session is closed ".

i.e iam passing an 'id' such that i can retrieve a record relevant to that id which is available in the database.


Is it because of improper TypeCasting betwen 'Object' and 'Student' types.
If so, tell me how to take care of this problem.



Immediate reply would be appreciated

Thanks,
Vijay