dev@glassfish.java.net

Re: SQLAnyhwhere: Is it OK to "fake" a sequence?

From: Lance J. Andersen <Lance.Andersen_at_Sun.COM>
Date: Wed, 10 Jan 2007 14:45:33 -0500

Hi Marina, Markus,


The SQL 2003 standard defines support for create sequence as well as
identity columns

SQL 2003 refers to Identity columns as internal sequence generator

SQL 2003 refers to 'create sequence' as an external sequence generator



Looking at the Persistence spec, I do not see what is the requirement
WRT what should happen when you specify either
@GeneratedValue(strategy=SEQUENCE/IDENTITY) and the specified strategy
is not supported (perhaps i missed it). This looks like an area that
should be clarified. So right now it looks to be implementation defined
(again unless i missed this as i only scanned the Persistence spec).

It sounds from Marina's comments below that a strategy of
SEQUENCE/IDENTITY are treated the same given the current Toplink
design. Marina please correct me if i am wrong.



Given that the SQL Standard supports both forms of sequence generators,
we should look at enhancing the code to support this as I suspect more
databases will adopt support for IDENTITY and CREATE SEQUENCE ala
PostgreSQL.


Regards
Lance
Marina Vatkina wrote:
> Hi Markus,
>
> This is a very good question, and at this point somewhat philosophical
> as well ;).
>
> TopLink code assumes that any particular database provides only one type
> of native sequence support, so it's for the user's benefit to get
> whatever
> is there even if they specified the other type. This is true for all
> but one
> tested database - PostgreSQL supports both types: identity and
> sequence, and
> its users can so far use the only the one that TopLink supports.
>
> Which means that unless you are willing to spend time and change the
> whole
> native sequence story, your "fake" solution is the one expected.
>
> thanks,
> -marina
>
> Markus KARG wrote:
>> Lance,
>>
>>> While, i am still not an expert on Toplink Essentials codeline yet,
>>> my take is that you are reading too much into the method names.
>>> Looking at this and the other platforms, this to me is just the way
>>> to access identity/sequences... etc.
>>> So I do not see you are faking a sequence, just providing the
>>> correct plumbing in order to provide the support required for the
>>> given platform, in this case, SQL Anywhere, to return the
>>> auto-generated values, which in this case is done via an identity
>>> column.
>>
>> Just for my own curiosity:
>>
>> A programmer can write @GeneratedValue(strategy = SEQUENCE) or
>> @GeneratedValue(strategy = IDENTITY), and he expects SQLAnywherePlatform
>> to do different things. Is SQLAynwherePlatform behaving correctly in the
>> case that SEQUENCE is used but not IDENTITY?
>>
>> Also, entity-persistent-tests is running tests using SEQUENCE. In fact
>> that tests failed. Then I added support for IDENTITY. Now the tests
>> pass. So it seems, the SEQUENCE tests think SQL Anywhere supports
>> sequences. But actually, it does not.
>>
>> Since I do not want to provide a lie, is it correct what I programmed,
>> or do I have to remove parts of it?
>>
>> Thanks
>> Markus
>