Hi,
I have 2 related questions which I would like to throw into the arena if I may.

1. I have created a user class in Hibernate which I return into XSP as an object like so:

public Object getUserdetails (int user_id)
{


Integer userID = new Integer(user_id);
Object userDetails;


try {
HibernateUtil Util = new HibernateUtil();
Session session = Util.currentSession();

Transaction transaction = session.beginTransaction();


//Get User details
User user = (User)session.load(test.User.class, userID);


//Return user details object
userDetails = user;


transaction.commit();
Util.closeSession();


} catch (HibernateException e) {
throw new RuntimeException("Exception in Hibernate:: " + e.getMessage(), e);
}


return userDetails;
}

As the User class getters are populated with user information, from with in the class I can do user.getFirstName() to retrieve the users firstname.

In my XSP page I read the object in as:

User2 usr2 = new User2();
Object userDetails = usr2.getUserdetails(42);

The problem arises when I try to access the object properties which I tried as :

String s = userDetails.getFirstName();

which gives me a language exception error: //start error (lines 171-171) "The method getFirstName() is undefined for the type Object" String s = userDetails.getFirstName(); // end error

How do I access the object to retrieve the user details?

2. Persisting the object in a Session.

Could I use session.setAttribute("userDetails", object)? If so, how would I access the object properties in this instance?

many thanks in advance

Reply via email to