You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Thomas Mahler <th...@web.de> on 2003/06/14 00:14:49 UTC

Re: about OJB (autoincrement fields)


JORGE IVAN MARMOLEJO wrote:
> Hi
> I have a problem with an autoincrement field with SQL server database, 
> table is the follow:
> create table Person(
> id int  primary key  IDENTITY (1, 1) NOT NULL ,
> nombre varchar(30));
> in this case OJB  intents to insert the id, which generates an error :
> [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert 
> explicit value for identity column in table 'test' when IDENTITY_INSERT 
> is set to OFF
> 
> the same problem occurs with autoincrement fields of  Mysql
> is there away to tell OJB, not to insert id in the test table, because 
> it's an autoincrement??

you can set access="readonly" in the fielddescriptor.
cheers,

>  
> how  can I  solve this problem?
>  
> thanks....
> 
> 
> *****************************************
> Jorge Ivan Marmolejo H.
> Ingeniero Java
> Universidad de San Buenaventura
> 
> jimarmol@yahoo.com
> jimarmol@hotmail.com
> 
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Free online calendar 
> <http://us.rd.yahoo.com/mail_us/tag/*http://calendar.yahoo.com> with 
> sync to Outlook(TM).


Re: about OJB (autoincrement fields)

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Steven,

----- Original Message -----
From: "Steven Robertson" <st...@fonem.com>
To: "OJB Users List" <oj...@db.apache.org>
Sent: Saturday, June 14, 2003 7:51 PM
Subject: Re: about OJB (autoincrement fields)


> Hello,
>
> I was interested in the same (i.e. using MySQL auto-increment values
for
> primary keys). I tried setting access="readonly" in the
field-descriptor,
> per the suggestion. This worked for objects created in isolation, but
> screwed up with objects linked using <collection-descriptor> or
> <reference-descriptor>.
>
> i.e.  say I have a parent object with a collection of child objects, I
> create them in memory then
>     .
>     broker.store(theparent);
>     .
>
> What happens is that parent and child object appear in the database
with
> MySQL auto-increment keys (starting from 1). However, the foreign key
> reference in the child object does not refer to the parent that
created it
> (i.e. its still using OJB generated indexes).

that's exactly one the problems when using Identity columns.
In current CVS you can find a sequence manager implementation
supporting Identity columns called SequenceManagerNativeImpl
(SequenceManagerMySQLImpl is outdated). More info see javadoc.
There is also a test case for hsql+MySQL called NativeIdentifierTest
in OJB test suite. This test is using references - seems
to work fine so far.

Check out current CVS.
Alternatively you can find sequence manager implementations
not using Identity columns under
http://db.apache.org/ojb/sequencemanager.html
or try to write your own sequence manager (I'm very interested in
new solutions ;-)).

regards,
Armin

>
> - Steven.
>
>
>
> ----- Original Message -----
> From: "Thomas Mahler" <th...@web.de>
> To: "JORGE IVAN MARMOLEJO" <ji...@yahoo.com>; "OJB Users List"
> <oj...@db.apache.org>
> Sent: Friday, June 13, 2003 11:14 PM
> Subject: Re: about OJB (autoincrement fields)
>
>
> >
> >
> > JORGE IVAN MARMOLEJO wrote:
> > > Hi
> > > I have a problem with an autoincrement field with SQL server
database,
> > > table is the follow:
> > > create table Person(
> > > id int  primary key  IDENTITY (1, 1) NOT NULL ,
> > > nombre varchar(30));
> > > in this case OJB  intents to insert the id, which generates an
error :
> > > [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot
insert
> > > explicit value for identity column in table 'test' when
IDENTITY_INSERT
> > > is set to OFF
> > >
> > > the same problem occurs with autoincrement fields of  Mysql
> > > is there away to tell OJB, not to insert id in the test table,
because
> > > it's an autoincrement??
> >
> > you can set access="readonly" in the fielddescriptor.
> > cheers,
> >
> > >
> > > how  can I  solve this problem?
> > >
> > > thanks....
> > >
> > >
> > > *****************************************
> > > Jorge Ivan Marmolejo H.
> > > Ingeniero Java
> > > Universidad de San Buenaventura
> > >
> > > jimarmol@yahoo.com
> > > jimarmol@hotmail.com
> > >
> >
> ----------------------------------------------------------------------
--
> > > Do you Yahoo!?
> > > Free online calendar
> > > <http://us.rd.yahoo.com/mail_us/tag/*http://calendar.yahoo.com>
with
> > > sync to Outlook(TM).
> >
> >
>
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>



Re: about OJB (autoincrement fields)

Posted by Steven Robertson <st...@fonem.com>.
Hello,

I was interested in the same (i.e. using MySQL auto-increment values for
primary keys). I tried setting access="readonly" in the field-descriptor,
per the suggestion. This worked for objects created in isolation, but
screwed up with objects linked using <collection-descriptor> or
<reference-descriptor>.

i.e.  say I have a parent object with a collection of child objects, I
create them in memory then
    .
    broker.store(theparent);
    .

What happens is that parent and child object appear in the database with
MySQL auto-increment keys (starting from 1). However, the foreign key
reference in the child object does not refer to the parent that created it
(i.e. its still using OJB generated indexes).

- Steven.



----- Original Message -----
From: "Thomas Mahler" <th...@web.de>
To: "JORGE IVAN MARMOLEJO" <ji...@yahoo.com>; "OJB Users List"
<oj...@db.apache.org>
Sent: Friday, June 13, 2003 11:14 PM
Subject: Re: about OJB (autoincrement fields)


>
>
> JORGE IVAN MARMOLEJO wrote:
> > Hi
> > I have a problem with an autoincrement field with SQL server database,
> > table is the follow:
> > create table Person(
> > id int  primary key  IDENTITY (1, 1) NOT NULL ,
> > nombre varchar(30));
> > in this case OJB  intents to insert the id, which generates an error :
> > [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert
> > explicit value for identity column in table 'test' when IDENTITY_INSERT
> > is set to OFF
> >
> > the same problem occurs with autoincrement fields of  Mysql
> > is there away to tell OJB, not to insert id in the test table, because
> > it's an autoincrement??
>
> you can set access="readonly" in the fielddescriptor.
> cheers,
>
> >
> > how  can I  solve this problem?
> >
> > thanks....
> >
> >
> > *****************************************
> > Jorge Ivan Marmolejo H.
> > Ingeniero Java
> > Universidad de San Buenaventura
> >
> > jimarmol@yahoo.com
> > jimarmol@hotmail.com
> >
> > ------------------------------------------------------------------------
> > Do you Yahoo!?
> > Free online calendar
> > <http://us.rd.yahoo.com/mail_us/tag/*http://calendar.yahoo.com> with
> > sync to Outlook(TM).
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>