0

type of object stored in session

asked 2022-08-17 00:04:14 +0800

softmasters gravatar image softmasters
1

Hello, I'm trying to retrieve an object from the session in the following way:

User loggedUser = (User) Executions.getCurrent().getSession().getAttribute( Constants.LOGGED_USER );

but I'm getting a ClassCastException at runtime saying I can't cast User to User. If I remove the cast in the code, I get a type mismatch at compile time.

I've tried to write:

Object test = Executions.getCurrent().getSession().getAttribute( Constants.LOGGED_USER );
log.info("user from session: " + test.getClass().getName());

And test is of type User.

How could I exit this deadlock? Thank you. Regards.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-17 15:01:46 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

Could you make sure both User belong to the same package? Maybe one is abc.User and another is def.User.

Maybe 2 User classes are created by different classloaders? see https://stackoverflow.com/questions/11865917/classcastexception-because-of-classloaders

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2022-08-17 00:04:14 +0800

Seen: 5 times

Last updated: Aug 17 '22

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More