db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Monroe <Greg.Mon...@dukece.com>
Subject RE: Primary key is set to the foreign key value
Date Thu, 03 Sep 2009 21:54:00 GMT
Hmm, only thing that I can think of is that you are using the
id broker method to autoincrement the numeric ids.  This may be
replacing the SSN with a number when you save the object.  Try 
adding the following attribute to your SSN column:


You might also consider using the "native" mode for autoincrement
as most modern SQL servers support this and it's faster and more
reliable than the idBroker code.

Also, from a general design perspective, you might want to add a 
separate ID column the Person_SSN table rather than use the SSN as 
the primary key. You can get into legal trouble is you pass SSN's 
around as keys and they become visible.  Much safer to have a 
unique ID not related to the SSN that can be passed.

> -----Original Message-----
> From: levko [mailto:lev.kozakov@yahoo.com]
> Sent: Thursday, September 03, 2009 4:44 PM
> To: torque-user@db.apache.org
> Subject: Primary key is set to the foreign key value
> I have very simple DB schema, where the 1st table (Person) has PK 'id'
> and
> the 2nd table (Person_SSN) has FK 'person_id' referring to the 'id' field
> of
> the 'Person' table. The 'Person_SSN' table has its own PK 'ssn':
> <database name="test" defaultIdMethod="idbroker">
>   <table name="Person" description="Person Data">
>     <column name="ID"
>       javaName="PersonId"
>       required="true"
>       primaryKey="true"
>       type="INTEGER"
>       description="Person ID"/>
>     <column name="FULL_NAME"
>       javaName="FullName"
>       required="true"
>       type="VARCHAR" size="128"
>       description="Full Name"/>
>     <column name="EMAIL"
>       javaName="EMailAddress"
>       required="true"
>       type="VARCHAR" size="128"
>       description="EMail Address"/>
>     <unique>
>       <unique-column name="EMAIL"/>
>     </unique>
>   </table>
>   <table name="Person_SSN" description="Person SSN">
>     <column name="PERSON_ID"
>       javaName="PersonId"
>       required="true"
>       type="INTEGER"
>       description="Foreign key Person"/>
>     <column name="SSN"
>       required="true"
>       primaryKey="true"
>       type="CHAR" size="9"
>       description="SSN"/>
>     <foreign-key foreignTable="Person" onDelete="cascade">
>       <reference local="PERSON_ID" foreign="ID"/>
>     </foreign-key>
>   </table>
> </database>
> When I create 'PersonSsn' object, I set SSN to '123456789', but the DB
> record shows that  SSN value is the same as the PERSON_ID value. I use
> Torque 3.3 and PostgreSQL 8.4.0.
> Could you, please, help me to understand what's the problem here?
> I've uploaded the source files. The test driver is in the lk.test.TestOM
> class.
> Thanks in advance for any idea,
> -- Lev http://www.nabble.com/file/p25283761/Test.zip Test.zip
> --
> View this message in context: http://www.nabble.com/Primary-key-is-set-
> to-the-foreign-key-value-tp25283761p25283761.html
> Sent from the Apache DB - Torque Users mailing list archive at
> Nabble.com.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org

DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

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

View raw message