Nino,
all is fine now. thanks for your help ;-)
On 3 Feb 2004, at 15:25, Nuno Santos wrote:

You need to type cast to access the methods. Try :
        ((UserDetail)userDetails).getFirstName()

On Tue, 2004-02-03 at 15:14, beyaNet Consultancy wrote:
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:


<color><param>7676,0F0F,5050</param>public</color> Object getUserdetails (<color><param>7676,0F0F,5050</param>int</color> user_id)

{



                Integer userID = <color><param>7676,0F0F,5050</param>new</color>
Integer(user_id);

Object userDetails;



<color><param>7676,0F0F,5050</param>try</color> {

                        HibernateUtil Util =
<color><param>7676,0F0F,5050</param>new</color> HibernateUtil();

Session session = Util.currentSession();


Transaction transaction = session.beginTransaction();




<color><param>2323,6E6E,2525</param>//Get User details</color>

User user =
(User)session.load(test.User.<color><param>7676,0F0F,5050</ param>class</color>,
userID);




<color><param>2323,6E6E,2525</param>//Return user details object</color>

userDetails = user;



transaction.commit();

Util.closeSession();



                        } <color><param>7676,0F0F,5050</param>catch</color>
(HibernateException e) {

                    <color><param>7676,0F0F,5050</param>throw</color>
<color><param>7676,0F0F,5050</param>new</color>
RuntimeException(<color><param>8989,1313,1515</param>"Exception in
Hibernate:: "</color> + e.getMessage(), e);

}



<color><param>7676,0F0F,5050</param>return</color> 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();<fixed>


</fixed>Object userDetails =
usr2.getUserdetails(<color><param>0000,0000,FFFF</param>42</color>);


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
--
Nuno Santos <[EMAIL PROTECTED]>


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to