-->
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.  [ 5 posts ] 
Author Message
 Post subject: Latest version breaking changes....
PostPosted: Thu Aug 14, 2008 6:23 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
Hibernate version:
2.1.0 alpha1

I need some help figuring out some changes between 1.2.1 and 2.1.0

Question 1:
I used to do this:
Code:
LazyInitializer li = NHibernateProxyHelper.GetLazyInitializer((INHibernateProxy)item);


The GetLazyInitializer method is now gone, how do I initialize a proxy now?



Question 2:
To handle partial collections and unitialized collections I used to do this:

Code:
       
        /// <summary>
        /// Explicitly sets the collection to initialized without going to the
        /// database, this can be hazerdous because it tells nHibernate that
        /// the collection as it sits is fully loaded.
        /// </summary>
        public virtual void ManualInitialize()
        {
            try
            {
                if (!(this.WasInitialized))
                {
                    this.SetInitialized();
                    bag = new K();

                    this.Session.GetSessionImplementation()
                           .GetCollectionEntry(this)
                                .InitSnapshot(this, Session.GetSessionImplementation().GetCollectionEntry(this).LoadedPersister);

                    this._WasManuallyInitialized = true;
                }
            }
            catch (Exception)
            {

                throw;
            }


this whole process seems to have changed, how can I fool the framework into thinking the collection is valid?

I go this far:
this.Session.PersistenceContext.GetCollectionEntry(this)

however, the InitSnapshot is gone along with the AddCollection methods from sessionimpl where or how is this done?


Question 3:
What happened to the ISessionFactory.ConnectionProvider? I used to reflect into it to get the connection string is there a different/better way to accomplish this now?



I realize that 2.1.0 is a bleeding edge build but I need some functionality that is in there so hopefully all these things can accomplished.


Question 4:
I noticed this:
Code:
public class SchemaUpdate


Does this do what it implies and does it actually function??? That would be like Christmas :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 4:55 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
Anyone have any ideas here?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 10:50 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
I have found the answer to part of this:

Quote:
Question 1:
I used to do this:

LazyInitializer li = NHibernateProxyHelper.GetLazyInitializer((INHibernateProxy)item);



Code:
if ([instance].[Property] is INHibernateProxy)
{
     ILazyInitializer init = ((INHibernateProxy)[instance].[Property]).HibernateLazyInitializer;

     if (init.IsUninitialized)
          return null;
     else
          reuturn ([Class Type])init.GetImplementation();
}


obviously, [instance] [property] and [Class Type] need to be replaced with the apprpriate code.

You can also call:
Code:
session.GetSessionImplementation().PersistenceContext.Unproxy(object);


However, it requires that you do this in the session and be aware that if the proxy is not initialized it will throw an exception.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 6:32 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
Quote:
Question 3:
What happened to the ISessionFactory.ConnectionProvider? I used to reflect into it to get the connection string is there a different/better way to accomplish this now?


Okay, answering another one. You have to cast the SessionFactory (assuming you are using the stock session factory) to a ISessionFactoryImplementor, then you can get to the property ConnectionProvider.


In my case the _Factory is a singleton of type ISessionFactory

Code:
private static string GetConnectionString()
{

     if (_Factory != null)
     {
           Type typeOfConnectionProvider = typeof(NHibernate.Connection.DriverConnectionProvider);
           PropertyInfo ConnectionStringPropertyInfo = typeOfConnectionProvider.GetProperty(
                "ConnectionString",
                BindingFlags.Instance | BindingFlags.NonPublic);
          string connectionString = (string)ConnectionStringPropertyInfo.GetValue(((ISessionFactoryImplementor)_Factory).ConnectionProvider, null);
          return connectionString;
     }
     else
          return null;

}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 23, 2008 5:14 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
Quote:
Question 2:
To handle partial collections and unitialized collections I used to do this:


Another answer:
Code:

        public virtual void ManualInitialize()
        {
            try
            {
                if (!(this.WasInitialized))
                {
                    this.SetInitialized();
                    InternalCollection = new K();

                    this.Session.PersistenceContext
                           .GetCollectionEntry(this).PostInitialize(this);
                             
                    this._WasManuallyInitialized = true;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.