Open dari220 opened 1 year ago
Strange, but reading same sql with JpaPagingItemReader works. Fetching gives expexted result.
Thank you for opening this issue. We do not exclude that this could be a bug in Spring Batch. However, we would like to validate that with a minimal complete verifiable example (the definition of UserDetails
and PersonExtendedImpl
are missing).
Could you please take some time to create a minimal example that reproduces the problem? To help you in reporting your issue, we have prepared a project template that you can use as a starting point. Please check the Issue Reporting Guidelines for more details about this.
Thank you for your collaboration.
Thank for taking your time.
At the moment I can provide this ziped Maven Spring Project.
Model contains three entities. User(=parent) and two childs UserRole and Privilege. Please run the Project not in test mode but as it is. I'm displayig ItemReader results in console or log file.
Please,
Sorry, but Im not experienced with inMemory database h2. It didn't worked for me at the moment. The issue with the JpaCursorItemReader appears when fetching multiple entities. Returns always 1 child entity. (Source file UserReader.java). This is the hql
SELECT DISTINCT u from User u LEFT JOIN FETCH u.userRoles ur LEFT JOIN FETCH u.privileges pr
I think, fetching multiple entities in one hql should work and makes sense when mutiplicity between entities is low. Darius Gurjazkas
hey @dari220 still your problem is pending so can i work on it
Hi @dari220, When fetching the user entity based on the sql below, two child entities of the user are returned. But I don't know if this is the intended behavior for JpaCursorItemReader.
SELECT DISTINCT u from User u
LEFT JOIN u.userRoles ur
LEFT JOIN u.privileges pr
Hi @fmbenhassine, JpaPagingItemReader works fine in the case described by dari220, but JpaCursorItemReader does not work as desired in this case for JOIN FETCH. Is this the intended behavior for JpaCursorItemReader?
Bug description Fetching Entities(UserRole in ManyToOne association) described via jakarta.persistence.EmbeddedId in Spring Batch and with JpaCursorItemReader returns always a single value.
Example: User has two UserRoles with roleId1=1 and roleId2=4. In ItemProcessor I get always either roleId1 or roleI2 but not both.
Environment Spring boot 3.1.3, Spring Batch 5.0.3, Hibernate-Core 6.2.7
Entities
Steps to reproduce
This Step produces correct sql statement but just one UserRole fetched in List of userRoles.
SQL:
Important! I could not reproduce the same issue in Spring Boot 3.1.3 and Spring MVC application environment!!!
Expected behavior JpaItemReaders should fetch all associated Entities(UserRole's) into Collection of parent Entity(User).