blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Add tests to ensure all Spring-Data features still work when using Blaze-Persistence

Open beikov opened this issue 5 years ago • 4 comments

It seems native queries and/or named queries with projections don't work. We should add tests for that and ensure everything still works as intended.

beikov avatar Jun 02 '20 10:06 beikov

@beikov I cannot reproduce this. See the PR with added test cases. They all suceed - tested Spring-Data 1.11.x and 2.0.x

Mobe91 avatar Nov 22 '20 02:11 Mobe91

@beikov I have tried with the test app you sent me, everything seems to work there (no exceptions). So I think we can merge the additional tests I have created and close this issue.

Mobe91 avatar Nov 29 '20 02:11 Mobe91

You wouldn't see exceptions but see that a wrong query is executed that then triggers lazy loading

beikov avatar Nov 29 '20 10:11 beikov

I don't see any lazy loading issues. But I see some other problems. Here is the relevant log output:

2020-11-29 17:15:02.790  INFO 14392 --- [           main] com.modernsql.DemoRunner                 :  = = = Hierarchy (UP) = = =

2020-11-29 17:15:02.792 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.797 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.798 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.798 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.799  INFO 14392 --- [           main] com.modernsql.DemoService                : jpaTraverseTreeUp took 8.2971ms in 4 iterations
2020-11-29 17:15:02.803 DEBUG 14392 --- [           main] org.hibernate.SQL                        : WITH RECURSIVE prev (id, parent) AS (SELECT * FROM hierarchy WHERE id = ? UNION ALL SELECT h.* FROM hierarchy h JOIN prev p ON (p.parent = h.id)) SELECT * FROM prev
2020-11-29 17:15:02.811  INFO 14392 --- [           main] com.modernsql.DemoService                : jpaTraverseTreeUpPreloaded took 11.6631ms
2020-11-29 17:15:02.812 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.813 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.814 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.814 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.814  INFO 14392 --- [           main] com.modernsql.DemoService                : jpaTraverseTreeUp took 2.082ms in 4 iterations
2020-11-29 17:15:02.816 DEBUG 14392 --- [           main] org.hibernate.SQL                        : WITH RECURSIVE prev (id, parent) AS (SELECT * FROM hierarchy WHERE id = ? UNION ALL SELECT h.* FROM hierarchy h JOIN prev p ON (p.parent = h.id)) SELECT * FROM prev
2020-11-29 17:15:02.819  INFO 14392 --- [           main] com.modernsql.DemoService                : jpaTraverseTreeUpPreloaded took 3.4718ms
2020-11-29 17:15:02.877  INFO 14392 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: com.blazebit.persistence.integration.hibernate.Hibernate53LimitHandlingDialect
2020-11-29 17:15:02.883 DEBUG 14392 --- [           main] org.hibernate.SQL                        : with recursive HierarchyCte(id) AS( select hierarchy0_.id as col_0_0_ from hierarchy hierarchy0_ where hierarchy0_.id=? UNION ALL select hierarchy1_.parent as col_0_0_ from HierarchyCte hierarchyc0_ inner join hierarchy hierarchy1_ on (hierarchy1_.id=hierarchyc0_.id) ) select hierarchy0_.id as id1_1_, hierarchy0_.parent as parent2_1_ from hierarchy hierarchy0_ where hierarchy0_.id in (select hierarchyc1_.id from HierarchyCte hierarchyc1_)
2020-11-29 17:15:02.889  INFO 14392 --- [           main] com.modernsql.DemoService                : blazePersistenceTraverseTreeUp took 68.7885ms
2020-11-29 17:15:02.895 DEBUG 14392 --- [           main] org.hibernate.SQL                        : with recursive HierarchyCte(id) AS( select hierarchy0_.id as col_0_0_ from hierarchy hierarchy0_ where hierarchy0_.id=? UNION ALL select hierarchy1_.parent as col_0_0_ from HierarchyCte hierarchyc0_ inner join hierarchy hierarchy1_ on (hierarchy1_.id=hierarchyc0_.id) ) select hierarchy0_.id as id1_1_, hierarchy0_.parent as parent2_1_ from hierarchy hierarchy0_ where hierarchy0_.id in (select hierarchyc1_.id from HierarchyCte hierarchyc1_)
2020-11-29 17:15:02.899  INFO 14392 --- [           main] com.modernsql.DemoService                : blazePersistenceTraverseTreeUp took 8.7944ms

2020-11-29 17:15:02.900  INFO 14392 --- [           main] com.modernsql.DemoRunner                 :  = = = Hierarchy (DOWN) = = =

2020-11-29 17:15:02.900 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select hierarchy0_.id as id1_1_0_, hierarchy0_.parent as parent2_1_0_ from hierarchy hierarchy0_ where hierarchy0_.id=?
2020-11-29 17:15:02.903 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.909 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.909 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.910 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.911 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.911 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.912 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.912  INFO 14392 --- [           main] com.modernsql.DemoService                : jpaTraverseTreeDown took 11.9777ms
2020-11-29 17:15:02.914 DEBUG 14392 --- [           main] org.hibernate.SQL                        : WITH RECURSIVE prev (id, parent) AS (SELECT * FROM hierarchy WHERE id = ? UNION ALL SELECT h.* FROM hierarchy h JOIN prev p ON (h.parent = p.id)) SELECT * FROM prev
2020-11-29 17:15:02.917 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.918 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.918 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.919 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.919 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.919 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.919 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.920  INFO 14392 --- [           main] com.modernsql.DemoService                : jpaTraverseTreeDownPreloaded took 6.3104ms
2020-11-29 17:15:02.929  INFO 14392 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: com.blazebit.persistence.integration.hibernate.Hibernate53LimitHandlingDialect
2020-11-29 17:15:02.930 DEBUG 14392 --- [           main] org.hibernate.SQL                        : with recursive HierarchyCte(id) AS( select hierarchy0_.id as col_0_0_ from hierarchy hierarchy0_ where hierarchy0_.id=? UNION ALL select hierarchy1_.id as col_0_0_ from HierarchyCte hierarchyc0_ inner join hierarchy hierarchy1_ on (hierarchy1_.parent=hierarchyc0_.id) ) select hierarchy0_.id as id1_1_, hierarchy0_.parent as parent2_1_ from hierarchy hierarchy0_ where hierarchy0_.id in (select hierarchyc1_.id from HierarchyCte hierarchyc1_)
2020-11-29 17:15:02.937 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.938 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.938 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.939 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.939 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.939 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.939 DEBUG 14392 --- [           main] org.hibernate.SQL                        : select children0_.parent as parent2_1_0_, children0_.id as id1_1_0_, children0_.id as id1_1_1_, children0_.parent as parent2_1_1_ from hierarchy children0_ where children0_.parent=?
2020-11-29 17:15:02.940  INFO 14392 --- [           main] com.modernsql.DemoService                : blazePersistenceTraverseTreeDown took 18.2623ms

The first invocation of blazePersistenceTraverseTreeUp takes a crazy 68.7885ms compared to the first invocation of jpaTraverseTreeUpPreloaded (11.6631ms). The second invocation of blazePersistenceTraverseTreeUp is when caching should kick in but it still takes more than twice as long as the second invocation of jpaTraverseTreeUpPreloaded (3.4718ms vs 8.7944ms).

A similar pattern can be seen when looking at the down traversals, though the differences are not that high.

Mobe91 avatar Nov 30 '20 01:11 Mobe91