I see this is expected behavior, but I think it is quite dangerous. Many of the user probably don’t read the manual really carefully when using this method (as we did neither). They probably just want to get a java-stream, and in the javadoc of the method (jakarta.persistence.TypeQuery) there seems to be no danger. Additionally, that occurs is not the fault easy to find as it relays on the sorting of the data in the DB. When creating unit-test most often with the small amount of data it is not triggered or the data is added the same order as it is read. I see multiple possibilities that could help to reduce the risk for this error:
- Fail on executing the query if it is not sorted by entity
- Log a warning if it occurs that a database-row is ignored because the entity was already created
- Only allow to use the streaming if a certain flag is set, this would force to read the doc.
|