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

Unable to use custom UserType in when #1286

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

Comments

Projects
None yet
2 participants
@martinsefcik

martinsefcik commented Mar 28, 2015

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());
        }
    }
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment