Skip to content
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

Weird Behavior for byte[] array in Hibernate Objects #1431

Closed
voor opened this issue Jul 10, 2015 · 3 comments
Closed

Weird Behavior for byte[] array in Hibernate Objects #1431

voor opened this issue Jul 10, 2015 · 3 comments
Milestone

Comments

@voor
Copy link

@voor voor commented Jul 10, 2015

Attempting to utilize a class that has a field mapping byte[] to Blob. Getting the following error:

[B cannot be cast to [Ljava.lang.Object;
! java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
! at com.querydsl.jpa.hibernate.HibernateUtil.setValue(HibernateUtil.java:71) ~[querydsl-jpa-4.0.2.jar:na]
! at com.querydsl.jpa.hibernate.HibernateUtil.setConstants(HibernateUtil.java:63) ~[querydsl-jpa-4.0.2.jar:na]
! at com.querydsl.jpa.hibernate.AbstractHibernateQuery.createQuery(AbstractHibernateQuery.java:105) ~[querydsl-jpa-4.0.2.jar:na]
! at com.querydsl.jpa.hibernate.AbstractHibernateQuery.createQuery(AbstractHibernateQuery.java:97) ~[querydsl-jpa-4.0.2.jar:na]
! at com.querydsl.jpa.hibernate.AbstractHibernateQuery.fetch(AbstractHibernateQuery.java:174) ~[querydsl-jpa-4.0.2.jar:na]
@voor
Copy link
Author

@voor voor commented Jul 10, 2015

Looks like it's because a byte array is considered an array.

It's attempting to cast the array to an Object array, which you can't do with a byte array.

    private static void setValue(Query query, String key, Object val) {
        if (val instanceof Collection<?>) {
            query.setParameterList(key, (Collection<?>) val);
        } else if (val.getClass().isArray()) {
            query.setParameterList(key, (Object[]) val);
        } else if (TYPES.containsKey(val.getClass())) {
            query.setParameter(key, val, TYPES.get(val.getClass()));
        } else {
            query.setParameter(key, val);
        }
    }

Would this possibly fix it? (Or something similar)

    private static void setValue(Query query, String key, Object val) {
        if (val instanceof Collection<?>) {
            query.setParameterList(key, (Collection<?>) val);
        } else if (val.getClass().equals(byte[].class)) {
            ...
        } else if (val.getClass().isArray()) {
            query.setParameterList(key, (Object[]) val);
        } else if (TYPES.containsKey(val.getClass())) {
            query.setParameter(key, val, TYPES.get(val.getClass()));
        } else {
            query.setParameter(key, val);
        }
    }
@Shredder121
Copy link
Member

@Shredder121 Shredder121 commented Jul 11, 2015

Sorry for not commenting earlier.
As for your PR, I think that it can be solved using the TYPES map (if we reorder the statements, there are HibernateTypes for byte arrays to blobs, so it can be handled by Hibernate).

I do need to ask whether it was @timowest's intention to make it customizable.

@voor
Copy link
Author

@voor voor commented Jul 11, 2015

No worries, this is just a showstopper for me, and I wanted to do whatever I could to help it get resolved.

@timowest timowest added the progress label Jul 17, 2015
@timowest timowest added this to the 4.0.3 milestone Jul 31, 2015
@timowest timowest removed the progress label Jul 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.