Hibernate Books

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Strange error: "Cannot create an abstract class."
PostPosted: Sun Nov 13, 2011 7:32 pm 
Newbie

Joined: Sun Nov 13, 2011 7:17 pm
Posts: 1
Hi guys,

I'm not sure whether this is an NHibernate error, but I'm totally stumped and Google hasn't been able to provide an answer. Perhaps some of you have seen it before as I imagine what I'm trying to do is quite common...?

So, I've got a .NET MVC2 website (C#). When a user logs in, I persist the User object I get from NHibernate to the web-session. (I Evict it from the NHibernate session first to be on the safe side.)

Here is the relevant code for persisting the user following on log on:

Code:
var userRepository = DependencyFactory.Get<IUserRepository>();
var user = userRepository.GetByUserNameAndPassword(userName, password);

userRepository.Evict(user);

var statePersister = DependencyFactory.Get<IStatePersister>();
statePersister.State.CurrentUser = user;


...as you can see I'm using a simple repository pattern to wrap the NHibernate stuff, and I'm also using a state persister pattern to allow all session variables to be stored in a single Serializable strongly typed class.

The important bit from the persister is as follows:

Code:
public State State
        {
            get
            {
                lock (stateLock)
                {
                    var state = HttpContext.Current.Session[sessionKey] as State;

                    if (state == null)
                    {
                        state = new State();
                        HttpContext.Current.Session[sessionKey] = state;
                    }

                    return state;
                }
            }
        }


If I change my user object and then try and access the State class from the state persister, I get the following error

"Cannot create an abstract class."

...when I get to the line:

Code:
var state = HttpContext.Current.Session[sessionKey] as State;


Any one got any clues where to start looking with this? Any help gratefully received!

Thanks in advance,

Steve.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.