Jeff-Lewis / codesmith

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

Many-to-many relationship not generated when many-to-many tables FKs are part of a composite key #165

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create 2 tables with a primary key
2. Create a many-to-many table with a FK to each of the PKs above.
3. Make the 2 FKs a composite PK for the many-to-many table.

What is the expected output? What do you see instead?

There should be a many-to-many relationship between the 2 tables created in
step 1.  The relationship is not created because the FK is part of the
composite PK.

What version of the product are you using?

CodeSmith 5, nHibernate framework templates v1.1.5

Please provide any additional information below.

EntityManager is not building the relationship because the FK is part of
the composite PK.  I have a fix for this issue.  In the method GetToMany in
the EntityManager, if the table is explicity marked cs_ManyToMany, build
the relationship.  See attachment.

Original issue reported on code.google.com by eric...@gmail.com on 15 Oct 2009 at 3:10

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by shannon....@gmail.com on 15 Oct 2009 at 3:37

GoogleCodeExporter commented 9 years ago
Thank you for the report and the hot fix, it was very helpful in diagnosing the 
issue.
This has been fixed and committed to source control, it will be released in the 
next
version!

Original comment by tdupont...@gmail.com on 21 Oct 2009 at 5:22

GoogleCodeExporter commented 9 years ago
Hey guys,
I have similar issue:

What steps will reproduce the problem?
1. Create 2 tables X and Y, X with primary key and other Y with foreign key 
from X 
and column C
2. Make the  FK(from X) and column C in table Y  a composite PK.

What is the expected output? What do you see instead?

There should be a one-to-many relationship between the X - Y tables created in
step 1.  The relationship is not created because the FK is part of the
composite PK.

What version of the product are you using?

CodeSmith 5, nHibernate framework templates v1.1.5

I applied the many to many patch . it worked for many-to-many tables but not 
for one-
to-many tables.
Any thought?

Original comment by tand...@gmail.com on 11 Nov 2009 at 10:45

GoogleCodeExporter commented 9 years ago
The hot fix was not the same code used in the source tree, please try using our 
latest 
nightly build.
http://community.codesmithtools.com/nightly/

If this does not resolve the issue, please provide us with a copy of your 
schema so 
that we can recreate the issue.

Original comment by tdupont...@gmail.com on 12 Nov 2009 at 12:08

GoogleCodeExporter commented 9 years ago
Tables :

1) Parent
CREATE TABLE.T_CLIENT
(
  CLIENT_GID                   CHAR(36 BYTE)    NOT NULL,
  CLIENT_ID                    NUMBER(38)       NOT NULL,
  NAME                         VARCHAR2(128 BYTE) NOT NULL,
  DESCRIPTION                  VARCHAR2(512 BYTE),
  PRIMARY_URL                  VARCHAR2(2048 BYTE),
  CLIENT_SERVICE_LEVEL_CODE    VARCHAR2(128 BYTE) NOT NULL,
  CLIENT_STATUS_CODE           VARCHAR2(128 BYTE) NOT NULL,
  REGISTRATION_COMPLETED_FLAG  CHAR(1 BYTE)     DEFAULT 'N'                   NOT 
NULL,
  DELETED_IND                  NUMBER(38)       DEFAULT 0                     NOT 
NULL,
  VERSION                      NUMBER(38)       NOT NULL,
)

2)Child table
CREATE TABLE T_CLIENT_INDUSTRY_CODE
(
  INDUSTRY_CODE  VARCHAR2(128 BYTE)             NOT NULL,
  CLIENT_ID      NUMBER(38)                     NOT NULL
)
Primary Key:
ALTER TABLE T_CLIENT_INDUSTRY_CODE ADD (
  CONSTRAINT CPK_CLIENT_INDUSTRY_CODE
 PRIMARY KEY
 (CLIENT_ID, INDUSTRY_CODE)
Foreign Key:
ALTER TABLE T_CLIENT_INDUSTRY_CODE ADD (
  CONSTRAINT CFK_CLIENT_INDUSTRY_CODE_1 
 FOREIGN KEY (CLIENT_ID) 

Files generated:

Client: (No child relationship)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
namespace="NHibernate.Generated.BusinessObjects" 
assembly="NHibernate.Generated">
    <class name="NHibernate.Generated.BusinessObjects.Client, 
NHibernate.Generated" table="T_CLIENT" lazy="true"
    where="DELETED_IND=0">
    <id name="Id" column="CLIENT_ID">
      <generator class="assigned">
      </generator>
    </id>
    <version name="Version" column="VERSION" />
        <property name="ClientGid" column="CLIENT_GID" />
        <property name="Name" column="NAME" />
        <property name="Description" column="DESCRIPTION" />
        <property name="PrimaryUrl" column="PRIMARY_URL" />
        <property name="RegistrationCompletedFlag" 
column="REGISTRATION_COMPLETED_FLAG" />
    <property name="DeletedInd" column="DELETED_IND" />
</class>

</hibernate-mapping>

Client Industry Code: (no parent relation ship -> many-to-one)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
namespace="NHibernate.Generated.BusinessObjects" 
assembly="NHibernate.Generated">
    <class name="NHibernate.Generated.BusinessObjects.ClientIndustryCode, 
NHibernate.Generated" table="T_CLIENT_INDUSTRY_CODE" lazy="true">
        <composite-id>
            <key-property name="ClientId" column="CLIENT_ID" /> 
            <key-property name="IndustryCode" column="INDUSTRY_CODE" /> 
        </composite-id>
  </class>
</hibernate-mapping>

Original comment by tand...@gmail.com on 13 Nov 2009 at 6:19