-->
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.  [ 1 post ] 
Author Message
 Post subject: hbm2net code modification
PostPosted: Mon Feb 18, 2008 2:23 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
I am starting to use code generation with NHibernate and it is pretty awesome. I created my own renderer and everything was cooking along fine. I use my own meta tags etc... to generate my classes.

One of my mappings uses the option to have the subclass element be the first element in the mapping file to create the class mapping. It seemed that the code generator just ignored this class.

After some digging I found this line

Code:
ClassMapping superclass = (ClassMapping) allMaps[child.SuperClass];


in the FindParents(HashTable) method of CodeGenerator.cs to be the problem. Since my base class is a sub-class of another class, it will not be found by this method.

So, I created two new methods that will search the object tree recursivly.

Code:
        private static ClassMapping FindClass(string className)
        {
            try
            {
                ClassMapping returnValue = null;

                foreach (ClassMapping mapping in allMaps.Values)
                {
                    returnValue = FindClass(className, mapping);

                    if (returnValue != null)
                        break;
                }



                return returnValue;
            }
            catch (Exception)
            {

                throw;
            }
        }

        private static ClassMapping FindClass(string className, ClassMapping classMapping)
        {
            try
            {
                ClassMapping returnValue = null;

                if (classMapping.ClassName.FullyQualifiedName == className)
                    returnValue = classMapping;
                else
                {

                    foreach (ClassMapping mapping in classMapping.Subclasses)
                    {
                        returnValue = FindClass(className, mapping);
                        if (returnValue != null)
                            break;
                    }

                }

                return returnValue;

            }
            catch (Exception)
            {

                throw;
            }
        }


then I changed the following line:
Code:
ClassMapping superclass = (ClassMapping) allMaps[child.SuperClass];


to

Code:
ClassMapping superclass = FindClass(child.SuperClass);



This is for the event that you have this heirarchy:

ClassC: ClassB: ClassA

ClassA & ClassB are defined in one mapping file and ClassC is in another mapping file.


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.