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 Brijesh Sood <br...@intersolutions.stpn.soft.net> on 2003/08/27 13:52:20 UTC

MSAccess - Relationship problem with autoincrement

Hi Everybody , need urgent help ,someone can get sometime & help me it would be very appreciated

I m using Torque-3.0.2 with Odbc and MsAccess as the database.
want to use MsAccess Autonumber as the primary key for all tables i have and this key would be the part of relationship exists 
between different tables
,
In my database schema defined have two tables Projects , Segments
                                                                                 1:N   
there is one to many relationship between projects to segments table  projects---------->segments

Somehome i am able to configure torque properties file build.properties , torque.properties 
created project DB Schema file  As Follow , I don't want to use IdGenerator service and its not supported as i found with my DB
so i made defaultIdMethod as none, My db sql file generated containing primary key field with integer type but i changed this to
autoincrement & created my tables with insert-sql command the table generated in msaccess contains projectID in projects and segmentID
in segments table is autoincrement type , 


Original                             changed to >>>>>>>>>>
CREATE TABLE projects                            CREATE TABLE projects
(                                                {        
    projectID integer,                                projectID autoincrement,
    projectCode VARCHAR (128),                        projectCode VARCHAR (128),
    projectName VARCHAR (128),                        projectName VARCHAR (128),
    PRIMARY KEY(projectID)                            PRIMARY KEY(projectID)
);                                                );
 this changes i made to make create table with primary key autoincrement type 

now i wrote a sample application to test the relationship between this two tables
       
      Projects projects = new Projects ();
      projects.setProjectname("Addison ");
      projects.setProjectcode("Project");
      projects.save();
      
     Segments segments = new Segments ();
      segments.setSegmentname("segments ");
      segments.save();
 
     segments.setProjects(projects); // setting relationship

System.out.println("Project Primary key : "+projects.getProjectid());  ======>>> Project Primary key : 0 

after checking the MsAccess db i find the Foriegn Key projectID  in the Segments table is 0 , i have tried to 
print the primarykey value of projectID from projects tables it showing 0 after the insertation of record ,

I dont know why after insertation of record its not synching the primary key value with projectID field which is autonumber field 
generated by MsAccess & i would be used for the relationship management between different tables. where is the problem , how to
use MsAccess Autoincrement Fields as the primary .....
I have written everything in very details ,if  something is missing pls mail mee back i can provide the whole thing , its very important for meto resolve this issue.
waiting for reply

Rgds
Brijesh Sood


<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE database SYSTEM  "c:/torque/dtd/database_3_0_1.dtd">
<database  name="redms"  defaultIdMethod="none">

  <table name="projects" description="Projects Table" >
    <column
      name="projectID"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="projectID"/>
    <column
      name="projectCode"
      required="true"
      type="VARCHAR"
      size="128"
      description="Project Code"/>

    <column
      name="projectName"
      required="true"
      type="VARCHAR"
      size="128"
      description="Project Name"/>
  </table>
  
  <!---Segment Table -->
  <table name="segment" description="Segment Table">
    <column
      name="segmentID"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="segmentID"/>
      
    <column
      name="segmentName"
      required="true"
      type="VARCHAR"
      size="128"
      description="Segment Name"/>

    <column
      name="projectID"
      required="true"
      type="INTEGER"
      description="Foreign Key GIS1 Projects Table"/>

    <foreign-key foreignTable="projects">
      <reference
        local="projectID"
        foreign="projectID"/>
    </foreign-key>
  </table>
</database>