You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Stephan Wiesner <st...@stephan-wiesner.de> on 2003/03/29 18:05:16 UTC

foreign-key problems

Hi list, I have a problem with foreign-key elements. Below is my tiny 
database definition and I can generate the SQL, if I remove the 
foreign-key element. With it, I get a nullpointer exception, though.
Can anybody, please, enlighten me?

java.lang.NullPointerException
        at 
org.apache.torque.engine.database.model.Database.doFinalInitialization(Database.java:444)


<database
  name="immorate"
  defaultIdMethod="idbroker">

  <table name="customer" description="Customer of Bank">
    <column
      name="c_id"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="Customer Id"/>
    <column
      name="lastname"
      required="true"
      type="VARCHAR"
      size="100"
      description=""/>

  </table>
 
 
  <table name="account" description="Bank account">
    <column
      name="accountnumber"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="Account number"/>

    <foreign-key foreignTable="customer"
      >
      <reference
        local="c_id"
        foreign="c_id"/>
    </foreign-key>
  </table>  
</database>



Re: foreign-key problems

Posted by Stephan Wiesner <st...@stephan-wiesner.de>.
Okay, found the problem. Have to define it the other way round...

Stephan

Stephan Wiesner wrote:

> Hi list, I have a problem with foreign-key elements. Below is my tiny 
> database definition and I can generate the SQL, if I remove the 
> foreign-key element. With it, I get a nullpointer exception, though.
> Can anybody, please, enlighten me?
>
> java.lang.NullPointerException
>        at 
> org.apache.torque.engine.database.model.Database.doFinalInitialization(Database.java:444) 
>
>
>
> <database
>  name="immorate"
>  defaultIdMethod="idbroker">
>
>  <table name="customer" description="Customer of Bank">
>    <column
>      name="c_id"
>      required="true"
>      primaryKey="true"
>      type="INTEGER"
>      description="Customer Id"/>
>    <column
>      name="lastname"
>      required="true"
>      type="VARCHAR"
>      size="100"
>      description=""/>
>
>  </table>
>
>
>  <table name="account" description="Bank account">
>    <column
>      name="accountnumber"
>      required="true"
>      primaryKey="true"
>      type="INTEGER"
>      description="Account number"/>
>
>    <foreign-key foreignTable="customer"
>      >
>      <reference
>        local="c_id"
>        foreign="c_id"/>
>    </foreign-key>
>  </table>  </database>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>



Enforcing 'Not Null' Columns

Posted by Stephan Wiesner <st...@stephan-wiesner.de>.
Hi list,
when I create a table with columns set to 'Not Null' the generated Java 
code does not enforce this in any way. When I initialize an object 
without setting all required attributes and then try to store it, I get 
an SQL exception. Wouldn't it be more efficient to test this in the Java 
class, instead of relying on the database?


Stephan