zengcheng / codesmith

Automatically exported from code.google.com/p/codesmith
0 stars 0 forks source link

NHibernate Composite Key Mappings Error #77

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create databse schema
2. Configure NHibernate csp file.
3. Generate NHibernate files

What is the expected output? 
Should see proper mappings as well as properly structured objects to 
reflect all table relationships.

What do you see instead?
Essentially, only get one to one table to class mappings.  There are no 
child collection properties on the objects or in the mappings (i.e. one to 
many reltionships).

What version of the product are you using?
Codesmith 5.0.5 Revision 6362

Please provide any additional information below.

Please refer to Case 106098 for further specific informatio.

Original issue reported on code.google.com by stepwise...@gmail.com on 17 Mar 2009 at 1:00

GoogleCodeExporter commented 9 years ago
After some testing, we have determined that this issue is applicable to 
associations
with composite keys.
This is a known issue, currently we do not support Composite Foreign Keys; the
columns for the keys will be generated, but the associations will not.
We do intend to support this in the future.

Original comment by tdupont...@gmail.com on 17 Mar 2009 at 7:10

GoogleCodeExporter commented 9 years ago

Original comment by shannon....@gmail.com on 21 Apr 2009 at 3:58

GoogleCodeExporter commented 9 years ago

Original comment by tdupont...@gmail.com on 21 Apr 2009 at 4:38

GoogleCodeExporter commented 9 years ago
"We do intend to support this in the future."

1) When might this support become available?

2) If I was to attempt to support composite foreign keys on my own, what issues 
do I 
need to be aware of?

Original comment by slang0...@gmail.com on 17 Aug 2009 at 5:13

GoogleCodeExporter commented 9 years ago
Hi. I have the same problem.
I have a master table with a Unique key field called "IdPrimaNota".
This table has a relation with a Detail with composite key which is 
"IdPrimaNota -
NumeroRiga".
the result i wish to get is a hbm file with a <bag> with a reference to the 
detail
table. Likewise I wish to obtain a class with a IList<Detail> property.
When will you release an update?
I tried to use your suggest work aournd but the result is the same.

I have another problem.
To resolve this issue i've tried to modify NHibernateHelper Solution.
I compile the solution and then i put the generated dll in the 
Samples\v5.2\Templates\Frameworks\NHibernate\Common\NHibernateHelper 
directory.
I have a strange behaviour.
The modfies i have made don't have any effect.
I had the doubt that i have placed the new dll in a wrong path but i suppose is
correct because if i delete the dll, generate process give me an error.

If i raname a method (Init for example) generate process give me an error
but if i modify a method inserting an exception everything is ok !!
I have inserted in a method some code that write a file to a  disk but never 
happens!!

So the question is: Until I'm waiting for your release..
How can i try to modify the generation process?

Original comment by m.cec...@gmail.com on 13 May 2010 at 9:16

GoogleCodeExporter commented 9 years ago
Today i've tried to modify NHibernateHelper project and use the dll in my 
CodeSmith
project.
i don't know but now my code has effect.

I resolve composite key generation only putting a comment in one row of code of
GetToMany() method of Entity Manager.cs
At the end of procedure there is this code:
   else if (!column.IsPrimaryKeyMember)
I've changed it in
   else //if (!column.IsPrimaryKeyMember)

this is the entire method

protected void GetToMany()
        {            
            foreach (TableKeySchema tks in _sourceTable.PrimaryKeys)
            {
                if (tks.ForeignKeyMemberColumns.Count > 1)
                {
                    GetMembers(_sourceTable.ForeignKeyColumns);
                }
                else
                {
                    ColumnSchema column = tks.ForeignKeyMemberColumns[0];

                    if (_associationMap.ContainsKey(column) ||
NHibernateHelper.IsExcludedColumn(column.Name))
                        return;

                    if (NHibernateHelper.IsManyToMany(column.Table))
                    {
                        TableSchema foreignTable = GetToManyTable(column.Table,
_sourceTable);
                        if (!_excludedTables.Contains(foreignTable))
                        {
                            EntityAssociation association = new
EntityAssociation(AssociationTypeEnum.ManyToMany, foreignTable, column);
                            _associationMap.Add(column, association);
                        }
                        else
                        {
                            GetMember(column);
                        }
                    }
                    else //if (!column.IsPrimaryKeyMember)
                    {
                        if (!_excludedTables.Contains(column.Table))
                        {
                            EntityAssociation association = new
EntityAssociation(AssociationTypeEnum.OneToMany, column.Table, column);
                            _associationMap.Add(column, association);
                        }
                        else
                        {
                            GetMember(column);
                        }
                    }
                }
            }                        
        }

Original comment by m.cec...@gmail.com on 13 May 2010 at 2:06