You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Brian McCallister <mc...@forthillcompany.com> on 2004/01/21 04:20:31 UTC

[bug] XDoclet M:N schema lacks FK constraints

Thomas D.,

Found another (small) problem with the xdoclet module. It isn't 
generating the foreign-key constraints in generated torque schema for 
M:N mappings. Take for example the following two classes and M:N 
collection:

/**
  * @ojb.class   table="GROUPS"
  *              documentation="A logical grouping of sources"
  */
public class Group
{
     /**
      * @ojb.field   primarykey="true"
      *              autoincrement="ojb"
      */
     private Integer id;

     /**
      * @ojb.collection element-class-ref="org.skife.suet.config.Source"
      *                 indirection-table="GROUP_SOURCE"
      *                 foreignkey="GROUP_ID"
      *                 remote-foreignkey="SOURCE_ID"
      *                 otm-dependent="true"
      */
     private Collection sources;
}

/**
  * @ojb.class   table="SOURCES"
  *              documentation="A source of information"
  */
public class Source
{
     /**
      * @ojb.field   primarykey="true"
      *              autoincrement="ojb"
      */
     private Integer id;

     /**
      * @ojb.field
      */
     private String uriString;

     /**
      * @ojb.field
      */
     private Timestamp added;
}

The generated torque schema is:

<database name="suet">
     <table name="GROUPS">
         <column name="id"
                 javaName="id"
                 type="INTEGER"
                 primaryKey="true"
                 required="true"
         />
     </table>
     <table name="GROUP_SOURCE">
         <column name="GROUP_ID"
                 type="INTEGER"
         />
         <column name="SOURCE_ID"
                 type="INTEGER"
         />
     </table>
     <table name="SOURCES">
         <column name="id"
                 javaName="id"
                 type="INTEGER"
                 primaryKey="true"
                 required="true"
         />
         <column name="uriString"
                 javaName="uriString"
                 type="VARCHAR"
                 size="24"
         />
         <column name="added"
                 javaName="added"
                 type="TIMESTAMP"
         />
     </table>
</database>

The GROUP_SOURCE table doesn't include the foreign key constraints.

-Brian



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [bug] XDoclet M:N schema lacks FK constraints

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Wed, 21 Jan 2004, Brian McCallister wrote:

> They are not required by OJB, but they are might nice to have in the 
> database.

Actually, I just added a flag to the torque sub task that allows to turn
generation of foreignkey tags off as I was having some problems with them
and Mysql (though it might have been a problem in my db model).
 
> Thank you again for the wonderful work you are doing with the module!

Why, thanks :-)

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [bug] XDoclet M:N schema lacks FK constraints

Posted by Brian McCallister <mc...@forthillcompany.com>.
They are not required by OJB, but they are might nice to have in the 
database.

Thank you again for the wonderful work you are doing with the module!

-Brian


On Jan 21, 2004, at 6:13 AM, Thomas Dudziak wrote:

> On Tue, 20 Jan 2004, Brian McCallister wrote:
>
>> Thomas D.,
>>
>> Found another (small) problem with the xdoclet module. It isn't
>> generating the foreign-key constraints in generated torque schema for
>> M:N mappings. Take for example the following two classes and M:N
>> collection:
>
> Well, not really a bug. I just didn't implement this yet ;-) I'll see
> whether I can add this today.
> BTW, are foreignkeys in the database (torque schema) required by OJB ?
>
> Tom
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [bug] XDoclet M:N schema lacks FK constraints

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Tue, 20 Jan 2004, Brian McCallister wrote:

> Thomas D.,
> 
> Found another (small) problem with the xdoclet module. It isn't 
> generating the foreign-key constraints in generated torque schema for 
> M:N mappings. Take for example the following two classes and M:N 
> collection:

Well, not really a bug. I just didn't implement this yet ;-) I'll see
whether I can add this today.
BTW, are foreignkeys in the database (torque schema) required by OJB ?
 
Tom



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [bug] XDoclet M:N schema lacks FK constraints

Posted by Thomas Dudziak <to...@first.gmd.de>.
Since nobody seems to know how to solve the problem, I took the
middleway. For m:n collections freignkeys are generated in the torque
schema as long as the collections are not inherited in subclasses.

Tom



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [bug] XDoclet M:N schema lacks FK constraints

Posted by Brian McCallister <mc...@forthillcompany.com>.
Almost embarassed to admit it but... I don't know =)

Can learn it reasonably quickly though and will get a response to you 
-- though I think others may be able to answer off the top of their 
heads.

-Brian

On Jan 25, 2004, at 5:06 AM, Thomas Dudziak wrote:

> Brian,
>
> I've currently implementing support for foreignkeys for collections 
> with
> indirection tables, and it would be good if you give me a hint how the
> resulting torque schema should look like in the case of
> inheritance. Consider for instance this simple model:
>
> /** @ojb.class */
> public class A
> {
>   /** @ojb.field primarykey="true" */
>   private int id;
>
>   /** @ojb.collection element-class-ref="B"
>     *                 foreignkey="AID"
>     *                 indirection-table="A_B"
>     */
>   private java.util.List bs;
> }
>
> /** @ojb.class */
> public class B
> {
>   /** @ojb.field primarykey="true" */
>   private String id;
>
>   /** @ojb.collection element-class-ref="A"
>     *                 foreignkey="BID"
>     *                 indirection-table="A_B"
>     */
>   private java.util.List as;
> }
>
> /** @ojb.class */
> public class C extends B
> {}
>
> Now, should the resulting schema look like this:
>
> <database name="ojbtest">
>     <table name="A">
>         <column name="id"
>                 javaName="id"
>                 type="INTEGER"
>                 primaryKey="true"
>                 required="true"
>         />
>     </table>
>     <table name="A_B">
>         <column name="AID"
>                 type="INTEGER"
>         />
>         <column name="BID"
>                 type="VARCHAR"
>                 size="24"
>         />
>         <foreign-key foreignTable="A">
>             <reference local="AID" foreign="id"/>
>         </foreign-key>
>         <foreign-key foreignTable="B">
>             <reference local="BID" foreign="id"/>
>         </foreign-key>
>     </table>
>     <table name="B">
>         <column name="id"
>                 javaName="id"
>                 type="VARCHAR"
>                 primaryKey="true"
>                 required="true"
>                 size="24"
>         />
>     </table>
>     <table name="C">
>         <column name="id"
>                 javaName="id"
>                 type="VARCHAR"
>                 primaryKey="true"
>                 required="true"
>                 size="24"
>         />
>     </table>
> </database>
>
> or should there also be foreignkeys to the table C ?
>
> Tom
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [bug] XDoclet M:N schema lacks FK constraints

Posted by Thomas Dudziak <to...@first.gmd.de>.
Brian,

I've currently implementing support for foreignkeys for collections with
indirection tables, and it would be good if you give me a hint how the
resulting torque schema should look like in the case of
inheritance. Consider for instance this simple model:

/** @ojb.class */
public class A
{
  /** @ojb.field primarykey="true" */
  private int id;

  /** @ojb.collection element-class-ref="B"
    *                 foreignkey="AID"
    *                 indirection-table="A_B"
    */
  private java.util.List bs;
}

/** @ojb.class */
public class B
{
  /** @ojb.field primarykey="true" */
  private String id;

  /** @ojb.collection element-class-ref="A"
    *                 foreignkey="BID"
    *                 indirection-table="A_B"
    */
  private java.util.List as;
}

/** @ojb.class */
public class C extends B
{}

Now, should the resulting schema look like this:

<database name="ojbtest">
    <table name="A">
        <column name="id"
                javaName="id"
                type="INTEGER"
                primaryKey="true"
                required="true"
        />
    </table>
    <table name="A_B">
        <column name="AID"
                type="INTEGER"
        />
        <column name="BID"
                type="VARCHAR"
                size="24"
        />
        <foreign-key foreignTable="A">
            <reference local="AID" foreign="id"/>
        </foreign-key>
        <foreign-key foreignTable="B">
            <reference local="BID" foreign="id"/>
        </foreign-key>
    </table>
    <table name="B">
        <column name="id"
                javaName="id"
                type="VARCHAR"
                primaryKey="true"
                required="true"
                size="24"
        />
    </table>
    <table name="C">
        <column name="id"
                javaName="id"
                type="VARCHAR"
                primaryKey="true"
                required="true"
                size="24"
        />
    </table>
</database>

or should there also be foreignkeys to the table C ?

Tom




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org