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 Glenn Barnard <ba...@hotmail.com> on 2004/04/13 22:09:46 UTC
Re: Primary Key from Insert
Armin,
I'm happy to report that version rc6 fixed my problem. Am now getting the
primary key returned in the data object upon insert with MS SQL Server.
I can now proceed full steam ahead with my development.
Thanks for your help a few weeks back.
>From: Armin Waibel <ar...@apache.org>
>Reply-To: "OJB Users List" <oj...@db.apache.org>
>To: OJB Users List <oj...@db.apache.org>
>Subject: Re: Primary Key from Insert
>Date: Thu, 18 Mar 2004 01:34:41 +0100
>
>Hi,
>
>Glenn Barnard wrote:
>
>>Armin:
>>
>>My suspicions are confirmed. JdbcAccessImpl closes its Statement after the
>>insert so that the SequenceManager must get another Statement (and,
>>therefore a new connection)
>
>why should the SequenceManager lookup a new connection after closing of the
>statement in JdbcAccessImpl??
>The connection used by the actual PB instance was managed by
>ConnectionManagerImpl class, this class is responsible to release the
>connection after use. During a PB-transaction always the same connection
>was used. On begin of the tx the connection was obtained, on commit or
>abort the connection was released.
>
>>in order to submit the SCOPE_IDENTITY() query.
>>
>>Looks like I've got some serious re-tooling to make this work!
>>
>>Before I consider that, let me ask one more question:
>>
>>If I do a BeginTransaction before all this, how does OJB/JDBC keep the
>>transactions coordinated among all the Statements so that the Commit
>>persists the data? It would seem that the broker would keep the
>>Statement/Connection and execute all the transactions with that same
>>object????
>>
>
>I don't understand again (sorry my bad understanding english)
>transactions? plural? With beginTransaction you start one PB-tx. One
>connection will be associated with the used PB-instance. Till the
>abort/commitTransaction call all sql operation use the same connection.
>Nested transaction are not supported.
>Sorry if I couldn't help you.
>
>regards,
>Armin
>
>>Thanks for being patient with me.
>>
>>>From: Armin Waibel <ar...@apache.org>
>>>Reply-To: "OJB Users List" <oj...@db.apache.org>
>>>To: OJB Users List <oj...@db.apache.org>
>>>Subject: Re: Primary Key from Insert
>>>Date: Wed, 17 Mar 2004 17:43:02 +0100
>>>
>>>Glenn Barnard wrote:
>>>
>>>>Armin, thanks for the direction. I've switched over to the
>>>>NativeSequenceManager. It calls lastInsertSelect() which in turn
>>>>invokes the supported platforms getLastInsertIdentity(). The platform
>>>>it's loading is the PlatformMsSQLServerImpl and it doesn't overload
>>>>PlatformDefaultImpl's stub for getLastInsertIdentity which throws a not
>>>>implemented exception.
>>>>
>>>>I'm back on version 1.4 and will upgrade immediately to 1.5. If that
>>>>version does not have the correct getLastInsertIdentity, then I will
>>>>have to look into implementing it elsewhere, perhaps by extending
>>>>PlatformMsSQLServerImpl with a custom getLastInsertIdentity method that
>>>>simply returns "SELECT SCOPE_IDENTITY() AS newID".
>>>>
>>>
>>>In rc5 method was not implemented.
>>>You can also use CVS version of OJB - it's stable (98%, to check you can
>>>run OJB junit test suite) and include identity column support in
>>>PlatformMsSQLServerImpl.
>>>
>>>regards,
>>>Armin
>>>
>>>>Thanks again for your help.
>>>>
>>>>
>>>>>From: Armin Waibel <ar...@apache.org>
>>>>>Reply-To: "OJB Users List" <oj...@db.apache.org>
>>>>>To: OJB Users List <oj...@db.apache.org>
>>>>>Subject: Re: Primary Key from Insert
>>>>>Date: Wed, 17 Mar 2004 15:49:44 +0100
>>>>>
>>>>>Hi Glenn,
>>>>>
>>>>>why don't you use a identity based sequence manager implementation?
>>>>>
>>>>>http://db.apache.org/ojb/sequencemanager.html#nativeSequenceManager
>>>>>
>>>>>(seems that one part of this section was "corrupted" by Maven, with
>>>>>"ant htmldoc" you can generate the local documentation)
>>>>>
>>>>>or your persistent capable objects can implement PersistenceBrokerAware
>>>>>interface and you assign the PK by hand in the afterInsert method
>>>>>(obtain connection from PB instance and perform sql query by your own).
>>>>>
>>>>>regards,
>>>>>Armin
>>>>>
>>>>>Glenn Barnard wrote:
>>>>>
>>>>>>
>>>>>>I'm using SQL Server 2000 and need to get the primary key returned in
>>>>>>the data model after an insert. My research shows that the query
>>>>>>"SELECT SCOPE_IDENTITY() AS newID" needs to be executed. What do I
>>>>>>need to do to get OJB to automatically populate the PK field in the
>>>>>>data model it returns?
>>>>>>
>>>>>>_________________________________________________________________
>>>>>>Get tax tips, tools and access to IRS forms all in one place at MSN
>>>>>>Money! http://moneycentral.msn.com/tax/home.asp
>>>>>>
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>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
>>>>>
>>>>
>>>>_________________________________________________________________
>>>>Free up your inbox with MSN Hotmail Extra Storage. Multiple plans
>>>>available. http://click.atdmt.com/AVE/go/onm00200362ave/direct/01/
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>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
>>>
>>
>>_________________________________________________________________
>>Get reliable access on MSN 9 Dial-up. 3 months for the price of 1!
>>(Limited-time offer)
>>http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/
>>
>>
>>---------------------------------------------------------------------
>>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
>
_________________________________________________________________
Get rid of annoying pop-up ads with the new MSN Toolbar FREE!
http://toolbar.msn.com/go/onm00200414ave/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org