Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Question on Native Sequence Implementation Choices..
Question on Native Sequence Implementation Choices.. [message #544016] Thu, 01 July 2010 11:16 Go to next message
Andrea Zoppello is currently offline Andrea ZoppelloFriend
Messages: 48
Registered: July 2009
Hi All,

I'm trying to understand looking at the code how the sequencing is supported by EclipseLink.

Basically i'm trying to use a sequencing approach that could both works for example with "MySQL" and "Oracle" without force me to do different persistence unit.

In particular i found that using the following annotation:

@SequenceGenerator(name="mycustom",sequenceName="SEQ_PROVA ", allocationSize=1)

EclipseLink is able to use the autoincrement field because mysql is supporting the autoidentityfields and not the sequencing.

So i was curious to know what would happen when the database support both ( for example H2 support both ) and i see from the following code from MetadataProject that eclipseLink use as default the "false" flag when istanting
the generator

Here the code i found:
for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
String sequenceGeneratorName = sequenceGenerator.getName();

String seqName;
if (sequenceGenerator.getSequenceName() != null && (! sequenceGenerator.getSequenceName().equals(""))) {
seqName = sequenceGenerator.getSequenceName();
} else {
// TODO: Log a message.
seqName = sequenceGeneratorName;

Integer allocationSize = sequenceGenerator.getAllocationSize();
if (allocationSize == null) {
// Default value, same as annotation default.
// TODO: Log a message.
allocationSize = new Integer(50);

NativeSequence sequence = new NativeSequence(seqName, allocationSize, false);
sequences.put(sequenceGeneratorName, sequence);

Now my question is:
It's possible to introduce a configuration parameter to let the user which approach to prefer when the database support both??

Now when both are supported the sequence approach is always used but from my point of view a good idea is to have this configurable...

Thnx in advance

Andrea Zoppello
Re: Question on Native Sequence Implementation Choices.. [message #544802 is a reply to message #544016] Mon, 05 July 2010 14:44 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can choose which to use using the strategy and GenerationType option of the GeneratedValue.

If you need to do something more complex, then using code in a SessionCustomizer to configure the sequences may be best. You could also define your own DatabasePlatform subclass to default the type of sequencing that you wish to use.

James : Wiki : Book : Blog : Twitter
Previous Topic:Query to MappedSuperclass fails
Next Topic:Foreign key to unique field not primary key problem
Goto Forum:

Current Time: Wed Jun 20 00:23:33 GMT 2018

Powered by FUDForum. Page generated in 0.02079 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top