Unable to use custom UserType in when #1286

Closed
martinsefcik opened this Issue Mar 28, 2015 · 0 comments

Projects

None yet

2 participants

@martinsefcik

I'm not able to use custom UserType in when statement in 3.6.0+. The following exception is always thrown.

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported constant Approved

It works fine with 3.5.1.

sample query:

QRequest r = QRequest.request;
JPAQuery q = new JPAQuery(em);
q.from(r);
q.orderBy(r.status.when(new Approved()).then(0).otherwise(1).asc());
q.list(r);

status field is defined as:

...
@Type(type = "com.xyz.status.StatusType")
private RequestStatus status;
...

StatusType is custom UserType which stores java object to database as string

...
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
        if (value == null) {
            st.setNull(index, StringType.INSTANCE.sqlType());
        } else {
            st.setString(index, value.getClass().getSimpleName());
        }
    }
...
@timowest timowest added the progress label Apr 1, 2015
@johnktims johnktims closed this in #1296 Apr 21, 2015
@timowest timowest removed the progress label May 9, 2015
@timowest timowest added this to the 4.0.0 milestone May 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment