db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashley Hayes <ashley.ha...@macalla.com>
Subject RE: MSAccess - Relationship problem with autoincrement
Date Thu, 28 Aug 2003 09:28:55 GMT
looking at torque3.1-alpha1 src code, 

org.apache.torque.oid.IDGeneratorFactory class defines the following method
to get an ID generator:


    public static IdGenerator create(DB dbAdapter)
    {
        String idMethod = dbAdapter.getIDMethodType();
        if (IDMethod.AUTO_INCREMENT.equals(idMethod))
        {
            return new AutoIncrementIdGenerator(dbAdapter);
        }
        else if (IDMethod.SEQUENCE.equals(idMethod))
        {
            return new SequenceIdGenerator(dbAdapter);
        }
        else
        {
            return null;
        }
    }


it does define the "AUTO_INCREMENT" id type but looking at more src code I
think it is going to cause problems because the
org.apache.torque.adapter.DBOdbc ( the DB adapter you use?) returns null
from method getIDMethodSQL .
 ( see also getIdAsVillageValue method of
org.apache.torque.oid.AutoIncrementIdGenerator )

I have no experience with MS Access-JDBC-AutoIncrement,but if you want the
IDGenerator to work, MS Access needs to support a query on the AutoIncrement
fields to get their next value WITHOUT inserting a new record, 

e.g. in oracle it is "SELECT MY_TABLE_SEQUENCE_NAME.nextval FROM DUAL" and
that's what you find in the Torque Oracle DB Adapter
(org.apache.torque.adapter.DBOracle)

   public String getIDMethodSQL(Object sequenceName)
    {
        return ("select " + sequenceName + ".nextval from dual");
    }

so if MS access does support a query to get an ID, you could extend the
org.apache.torque.adapter.DBOdbc class
overriding the method "public String getIDMethodSQL(Object obj)". I don't
know how to configure the Torque.properties to use this adapter but think
its easy...


am no expert but hope this helps,
Ashley

p.s. have a look at the latest code for the above classes, but don't think
they will have implemented the auto increment for ODBC as unless the ID
generation query was made configurable.









-----Original Message-----
From: Brijesh Sood [mailto:brijesh_sood@intersolutions.stpn.soft.net]
Sent: 28 August 2003 04:55
To: Apache Torque Users List
Subject: Re: MSAccess - Relationship problem with autoincrement


Hi Russel , Yea firstly i was using native as the IdGenerator , SQL schema
generated is same either u use native or none , i have to make
primarykey as autoincrement type and when i test my program for insertation
of data with idGenerator defaultIdMethod="native"
it gives me error
org.apache.torque.TorqueException: IdGenerator for table 'Projects' is null
        at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:690)
        at com.petris.BaseProjectsPeer.doInsert(BaseProjectsPeer.java:216)
        at com.petris.BaseProjectsPeer.doInsert(BaseProjectsPeer.java:564)
        at com.petris.BaseProjects.save(BaseProjects.java:313)
        at com.petris.BaseProjects.save(BaseProjects.java:275)
        at com.petris.BaseProjects.save(BaseProjects.java:255)
        at com.petris.TestDB.main(TestDB.java:30)
dont know where i m making mistake , u have any idea ,????

can u check this ...
is there any other setting ...?
waiting for reply
thanks
brijesh




From: "Russell Simpkins" <RussellSimpkins@funnygarbage.com>
To: "Apache Torque Users List" <torque-user@db.apache.org>
Sent: Wednesday, August 27, 2003 7:26 PM
Subject: RE: MSAccess - Relationship problem with autoincrement



Did you try setting the defaultIdMethod="native" when you set it to "none"
it really means "none".



-----Original Message-----
From: Brijesh Sood [mailto:brijesh_sood@intersolutions.stpn.soft.net]
Sent: Wednesday, August 27, 2003 7:52 AM
To: torque-user@db.apache.org; hps@intermeta.de
Subject: 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>




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


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

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


Mime
View raw message