These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: session.Load + MappingExeption (proxy problem?)
PostPosted: Wed Feb 20, 2008 9:25 pm 
Newbie

Joined: Wed Feb 20, 2008 9:15 pm
Posts: 11
Hello
I tried the 10.4.3. Application version checking
shown here: http://www.hibernate.org/hib_docs/nhibe ... ansactions .

My complete code looks like this:

Code:
            Configuration cfg = new Configuration();
            cfg.AddAssembly("NHibernateTests");

            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction trans = session.BeginTransaction();

User test = session.Load<User>("joe_cool");

            int oldvers = test.VVersion;
            test.EmailAddress = "newMail2222";
            session.Load(test, test.Id); <<<<<<<<Exception

In the last line an MappingException is thrown:
"Unknown entity class: CProxyTypeNHibernate_TestsUserNHibernate_Tests_NHibernate_ProxyINHibernateProxy1"

Where is my mistake?

/edit:
- The mapping file is correct. Saving a "user" works fine.
- Closing/disposing the session and using a new results in the same exception

Hibernate version: 1.2.1.GA

Full stack trace of any exception that occurs:
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass)
at NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass)
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)
at NHibernate.Impl.SessionImpl.DoLoadByObject(Object obj, Object id, LockMode lockMode)
at NHibernate.Impl.SessionImpl.Load(Object obj, Object id)
at NHibernate_Tests.Program.Main(String[] args) in [...]NHibernate Tests\NHibernate Tests\Program.cs:line 37
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Top
 Profile  
 
 Post subject: session.Load + MappingExeption (proxy problem?)
PostPosted: Thu Feb 21, 2008 5:35 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

The overload ISession.Load(Object, Object) is intended to populate an empty transient instance of your class. The instance you have passed is a persistent one.

Hope that helps.

Regards,
Richard

from the API doc:
Quote:
ISession.Load Method (Object, Object)

Read the persistent state associated with the given identifier into the given transient instance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 7:31 am 
Newbie

Joined: Wed Feb 20, 2008 9:15 pm
Posts: 11
Hi,

yes, the instance is an persistend one. But in the documentation

Quote:
// foo is an instance loaded by a previous Session
session = factory.OpenSession();
transaction = session.BeginTransaction();
int oldVersion = foo.Version;
session.Load( foo, foo.Key );
if ( oldVersion != foo.Version ) throw new StaleObjectStateException();
foo.Property = "bar";
session.Flush();
transaction.Commit();
session.close();


foo is also a already persisted object.


Top
 Profile  
 
 Post subject: session.Load + MappingExeption (proxy problem?)
PostPosted: Thu Feb 21, 2008 8:21 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

Quote:
foo is also a already persisted object.


I don't think it is ... in that example foo is an instance from an older (closed) session, so it's just a regular object.

In your example I think you had a persistent object from the current (open) session.

Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 9:17 am 
Newbie

Joined: Wed Feb 20, 2008 9:15 pm
Posts: 11
Ok. I understand now.

Changing the code to
Code:

            User test = session.Load<User>("joe_cool");
            test.EmailAddress = "newMail2222";
            session.Close();
            ISession newSession = factory.OpenSession();

            int oldvers = test.VVersion;
           
            newSession.Load(test, test.Id);// <<<<<<<<Exception


results in the same error.

Maybe I'm totally wrong. My plan was to get the Version from the Database and compare with the "local" version to see if there were changes made by another user.
Which is the right way to do that?


Top
 Profile  
 
 Post subject: session.Load + MappingExeption (proxy problem?)
PostPosted: Thu Feb 21, 2008 9:44 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

Personally I would use one of the other overloads of the Load() method.

You could use:
Code:
test = newSession.Load<User>(test.Id);


I think this will acheive the same thing you already wanted. Note, you will have a reference to a new persistent instance.

Regards,
Richard


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

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.