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

EntityViewRepository findAll(start,max) fails with ClassCastException #720

Closed
sharadborhade opened this issue Jan 19, 2019 · 25 comments · Fixed by #721

Comments

@sharadborhade
Copy link

commented Jan 19, 2019

findAll(start, max) method of the Repository fails with java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long for eclipselink embedded composite primary key. It works with hibernate 5.0.12.Final.

I am referring deltaspike-data-rest example with tomcat web server and CDI injection.

Expected behavior

findAll(start,max) should return the List<CompositeView>

Actual behavior

Exception is:
Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed calling Repository: [Repository=com.blaze.poc.CompositeViewRepository,entity=com.blaze.poc.CompositeKeyEntity,method=findAll,exception=class java.lang.reflect.InvocationTargetException,message=null
	at com.blazebit.persistence.deltaspike.data.impl.builder.EntityViewDelegateQueryBuilder.invoke(EntityViewDelegateQueryBuilder.java:118)
	at com.blazebit.persistence.deltaspike.data.impl.builder.EntityViewDelegateQueryBuilder.execute(EntityViewDelegateQueryBuilder.java:61)
	... 14 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.blazebit.persistence.deltaspike.data.impl.builder.EntityViewDelegateQueryBuilder.invoke(EntityViewDelegateQueryBuilder.java:113)
	... 15 more
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
	at com.blazebit.persistence.impl.PaginatedTypedQueryImpl.getResultList(PaginatedTypedQueryImpl.java:158)
	at com.blazebit.persistence.impl.PaginatedTypedQueryImpl.getResultList(PaginatedTypedQueryImpl.java:45)
	at com.blazebit.persistence.deltaspike.data.base.handler.AbstractEntityViewAwareRepositoryHandler.findAll(AbstractEntityViewAwareRepositoryHandler.java:286)
	... 20 more

Steps to reproduce

  1. Downloaded deltaspike-data-rest example
  2. Marked config beans to ApplicationScoped
  3. Created CompositeKeyEntity with embedded CompositePK and EntityView (CompositeView, CompositeIdView). CompositePK contains 2 fields (String, java.sql.Timestamp)
  4. Created CompositeViewRepository by extending EntityViewRepository<CompositeKeyEntity, CompositeView, CompositePK>.
  5. Created test class to test default repository methods. findBy method works, but findAll(0,10) fails.

Environment

Version: 1.3.1/1.3.0
JPA-Provider: Eclipselink 2.6.4, Deltaspike 1.8.1
DBMS: DB2 11 for z/OS, Driver: IBM Data Server Driver for JDBC and SQLJ Version: 4.21.29
Web Server: Tomcat, CDI

@beikov beikov self-assigned this Jan 20, 2019

@beikov beikov added bug core labels Jan 20, 2019

@beikov beikov added this to the 1.4.0 milestone Jan 20, 2019

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 20, 2019

Thanks for the report, but I couldn't reproduce it with H2 on the latest TomEE. I'm not sure, but this might be a DB2 + EclipseLink related issue

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 20, 2019

Thank you for the quick look, but I think the issue could be with blaze deltaspike/eclipselink integration as EntityRepository.findAll(start,max) method of deltaspike data works with DB2 + eclipselink, but when I use EntityViewRepository of blaze deltaspike integration then it fails with the ClassCastException.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 21, 2019

Do you think you could share that example via e.g. a PR? I just tried to reproduce this with DB2 but couldn't.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 21, 2019

I finally reproduced it. Configuring DB2 for TomEE was harder than I thought. Looking into this now

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 21, 2019

IMO this is an EclipseLink bug. I create a query like entityManager.createQuery("select count(*) from ...", Long.class) and rightfully expect the result to be of the type Long, but EclipseLink uses the type the JDBC driver provides, which in case of DB2 is Integer. I will try to workaround it, but this is almost certainly going to blow up at other places where you are using a count query as well.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 21, 2019

There is an open PR associated with this issue that contains the workaround. You can build it yourself for now if you want to give it a try. I will try to do a release later this week, but I can't promise anything yet.

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 21, 2019

Thanks. will check and confirm.

beikov added a commit to beikov/blaze-persistence that referenced this issue Jan 22, 2019
@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 22, 2019

Count query works, but it fails in next step with below exception.

DB2 SQL Error: SQLCODE=-199, SQLSTATE=42601, SQLERRMC=NULLS;FETCH , EXCEPT MINUS UNION ), DRIVER=4.21.29

SQL query works after removing NULLS LAST from order by. As per this link, DB2 for z/OS does not support NULLS LAST.

Deltaspike + Eclipselink + DB2 generates the query without NULLS LAST
Blaze + Deltaspike + Hibernate + DB2 works and generates the query without NULLS LAST

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 22, 2019

Seems like this is another EclipseLink issue. I can look into it, maybe we can automatically adapt the EclipseLink DatabasePlatform to yield the correct behavior.

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 22, 2019

Thanks

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 22, 2019

The latest push should fix the issues with the null precedence handling on DB2 with EclipseLink

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 23, 2019

I noticed EntityRepository.findAll(start, max) fails with NullPointerException.

Caused by: java.lang.NullPointerException
    at com.blazebit.persistence.deltaspike.data.impl.handler.EntityViewRepositoryHandler.idAttribute(EntityViewRepositoryHandler.java:97)
    at com.blazebit.persistence.deltaspike.data.base.handler.AbstractEntityViewAwareRepositoryHandler.findAll(AbstractEntityViewAwareRepositoryHandler.java:194)

It seems to be because of viewClass() being null in the EntityViewRepositoryHandler.idAttribute() method.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 23, 2019

Is the class for which it fails annotated with @EntityView?

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 23, 2019

No. I am using Deltaspike's EntityRepository<E,PK> which does not require view class. I am passing Entity class and PK class.
EntityViewRepositoryHandler seems to be handling the calls for Deltaspike's EntityRepository.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 23, 2019

Hmm, that's odd. I'll look into this, but probably won't be able to finish this today

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 23, 2019

I pushed something that should do it, but I wasn't able to do any further tests yet. Would be nice if you could let me know so I can take a deeper look tomorrow.

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 23, 2019

Thanks for the immediate fix. findAll(1,10) works, but it is fetching more records than expected. It seems offset needs to be set to the query.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 24, 2019

Sorry for the issues, this one was an oversight. We mainly tested the entity view parts and apparently didn't notice that the entity related stuff was partly non-functional. I pushed the fix to the PR. When you are done testing/evaluating, I will do another release.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 28, 2019

@sharadborhade can you confirm it works as expected now? I'd like to do a release this week with all those fixes.

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Jan 28, 2019

null precedence issue 723 still exists. Other issues are fixed.

I noticed getDbms method returns null dbms.

Issue is with Eclipse + DB2 for z/OS. As per IBM documentation, DB2 for Linux, UNIX, and Windows supports NULLS LAST.

@beikov

This comment has been minimized.

Copy link
Member

commented Jan 28, 2019

Yeah you are right, I forgot to implement getDbms for eclipselink 🤦‍♂️

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Feb 7, 2019

@beikov, any update on the null precedence issue?

@beikov

This comment has been minimized.

Copy link
Member

commented Feb 7, 2019

The PR #721 should fix the issue. I'm about to merge that now. Would be great if you could verify it works properly

@sharadborhade

This comment has been minimized.

Copy link
Author

commented Feb 8, 2019

Still facing the same issue. NULLS LAST is appended to the sql query and sql query fails with below issue.

DB2 SQL Error: SQLCODE=-199, SQLSTATE=42601, SQLERRMC=NULLS;FETCH , EXCEPT MINUS UNION ), DRIVER=4.21.29
@beikov

This comment has been minimized.

Copy link
Member

commented Feb 10, 2019

Found the issue, I forgot to enable the workaround/optimization. I tested it now and can confirm that tests which failed before, are now running fine.

@beikov beikov closed this in #721 Feb 25, 2019

beikov added a commit that referenced this issue Feb 25, 2019
beikov added a commit to beikov/blaze-persistence that referenced this issue Feb 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.