Change datatype of a sequence H2DB

You could create you own patched version of H2, if you are allowed to replace the H2 jar file.

In org.h2.expression.Function change

    addFunctionNotDeterministic("NEXTVAL", NEXTVAL,
            VAR_ARGS, Value.LONG); 

to

    addFunctionNotDeterministic("NEXTVAL", NEXTVAL,
            VAR_ARGS, Value.DECIMAL);

and in org.h2.expression.SequenceValue change

@Override
public Value getValue(Session session) {
    long value = sequence.getNext(session);
    session.setLastIdentity(ValueLong.get(value));
    return ValueLong.get(value);
}

@Override
public int getType() {
    return Value.LONG;
} 

to

@Override
public Value getValue(Session session) {
    long lv = sequence.getNext(session);
    ValueDecimal value = ValueDecimal.get(BigDecimal.valueOf(lv)); 
    session.setLastIdentity(value);
    return value;
}

@Override
public int getType() {
    return Value.DECIMAL;
} 

Tags:

Java

Oracle

H2