Question on Native Sequence Implementation Choices.. [message #544016] |
Thu, 01 July 2010 07:16  |
Eclipse User |
|
|
|
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:
@Id
@Column(name="ID_PROVA")
@GeneratedValue(generator="mycustom")
@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);
sequence.setQualifier(sequenceGenerator.getQualifier());
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 10:44  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05626 seconds