Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Old Sequence behavior on "long id" is broken by Rev 2000 under bug#220394 - improve insert performance


Old Sequence behavior on "long id" is broken by Rev 2000 under
bug#220394 -improves insert performance.

I have an application that works in many previous version of TopLink.
However, on EclipseLink, it doesn't work anymore.

Most but not all of my domain objects use "long id" for mapped primary
key. Default initialization in Java for long is 0. So our application
99% of all objects setup the mapping to tell that attribute "id"
"default null value" is Long == 0 using TopLink/EclipseLink workbench.

We do communicate to TopLink that id == 0 is equivalent to null but the
new sequence code doesn't care anymore about what we specify. We see the
new code has removing a feature and making the Workbench "default null
value" feature most of the time useless in our case. 

You probably already heard of the "Null Pattern". That's why we avoid
using Long instead of "long". With Java 5 it's even worst, if we use
Long and some client code expect "long" Java will do an implicit cast
but at runtime will throw NullPointerException.

It looks weird from the client code that we call assignSequenceNumber
when our sequence field in not explicitly initialized and the method
refuse to assign the sequence.

I really doubt that that checking what is the definition of null in the
descriptor for the field involved can be visible in a profiler.

The guilty method is: 

    public Object assignSequenceNumber(Object object, AbstractSession
writeSession) throws DatabaseException {
        DatabaseField sequenceNumberField =
        Object existingValue = getBaseValueForField(sequenceNumberField,
        // If the value is null or zero (int/long) return.
        // PERF: The (internal) support for letting the sequence decide
this was removed,
        // as anything other than primitive should allow null and
default as such.
        if (existingValue != null &&
!Helper.isEquivalentToNull(existingValue)) {
            return null;

     * Check if the value is null, or 0 (int/long) for primitive ids.
    public static boolean isEquivalentToNull(Object value) {
        return (value == null)
                        || (!isZeroValidPrimaryKey
                                && (((value.getClass() ==
ClassConstants.LONG) && (((Long)value).longValue() == 0L))
                                        || ((value.getClass() ==
ClassConstants.INTEGER) && (((Integer)value).intValue() == 0))));

Back to the top