New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot serialize using literals when null included in expression #1079

Closed
giveadamakick opened this Issue Dec 9, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@giveadamakick

I have the following update statement:

public Long apply(final SQLUpdateClause update)
{
    return update
            .where(MY_TABLE.ID.eq(id))
            .setNull(MY_TABLE.SOMETHING)
            .execute();
}

As part of my Configuration, I have an SQLListener implementation that logs all SQL generated using an SQLSerializer (so for the update statement above, serializer.serializeUpdate() is called). I call setUseLiterals(true) on the serializer I use.

This throws the following exception when it attempts to serialize the SQL:

java.lang.IllegalArgumentException: Found no type for com.mysema.query.sql.types.Null
    at com.mysema.query.sql.JavaTypeMapping.getType(JavaTypeMapping.java:133)
    at com.mysema.query.sql.Configuration.asLiteral(Configuration.java:89)
    at com.mysema.query.sql.SQLSerializer.visitConstant(SQLSerializer.java:729)
    at com.mysema.query.support.SerializerBase.visit(SerializerBase.java:208)
    at com.mysema.query.support.SerializerBase.visit(SerializerBase.java:42)
    at com.mysema.query.types.ConstantImpl.accept(ConstantImpl.java:127)
    at com.mysema.query.support.SerializerBase.handle(SerializerBase.java:105)
    at com.mysema.query.sql.SQLSerializer.serializeForUpdate(SQLSerializer.java:574)
    at com.mysema.query.sql.SQLTemplates.serializeUpdate(SQLTemplates.java:800)
    at com.mysema.query.sql.SQLSerializer.serializeUpdate(SQLSerializer.java:544)
    at com.atlassian.pocketknife.api.querydsl.LoggingSqlListener.getUpdateSql(LoggingSqlListener.java:202)
    at com.atlassian.pocketknife.api.querydsl.LoggingSqlListener.notifyUpdate(LoggingSqlListener.java:106)

I'm able to work around this by calling configuration.register(new NullType()) on the configuration used when executing the update, where NullType is this class I created:

public class NullType extends AbstractType<Null>
    {
        public NullType() {
            super(Types.NULL);
        }

        @Override
        public Null getValue(ResultSet rs, int startIndex) throws SQLException {
            return Null.DEFAULT;
        }

        @Override
        public Class<Null> getReturnedClass() {
            return Null.class;
        }

        @Override
        public void setValue(PreparedStatement st, int startIndex, Null value)
                throws SQLException {

            if(isNotEmpty(getSQLTypes()))
            {
                st.setNull(startIndex, getSQLTypes()[0]);
            }
            else
            {
                throw new RuntimeException("Unable to set database column to null");
            }
        }

        @Override
        public String getLiteral(final Null value)
        {
            return "null";
        }
    }

Null is a pretty standard database type, so I think this should be part of the default supported types (defaultTypes in JavaTypeMapping).

@timowest timowest added this to the 4.0.0 milestone Dec 9, 2014

@timowest timowest added the bug label Dec 9, 2014

@Shredder121 Shredder121 closed this in #1081 Dec 12, 2014

@timowest timowest modified the milestones: 3.6.1, 4.0.0 Dec 17, 2014

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jan 31, 2015

Member

Released in 3.6.1

Member

timowest commented Jan 31, 2015

Released in 3.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment