javax.persistence.NonUniqueResultException: query did not return a unique result: 2 (this error happens only through Heroku server-free option)
See original GitHub issueWhen I send put request Log in locally and then test it via Postman it works perfectly fine, but when I do through Heroku server sometimes unexpectedly it adds 2 device info on the same user into DB, which leads to ambiguous situation in DB, my problem is I am not sure where exactly the problem, whether it’s with the project code, or with Heroku server, because if you’re using the free Heroku option it falls asleep in a while, so maybe that’s the key, and that’s why I have this error.
There are all logs from Heroku server down below:
DEBUG SQL select userdevice0_.user_device_id as user_dev1_8_, userdevice0_.created_at as created_2_8_, userdevice0_.updated_at as updated_3_8_, userdevice0_.device_id as device_i4_8_, userdevice0_.device_type as device_t5_8_, userdevice0_.is_refresh_active as is_refre6_8_, userdevice0_.notification_token as notifica7_8_, userdevice0_.user_id as user_id8_8_ from user_device userdevice0_ left outer join users user1_ on userdevice0_.user_id=user1_.user_id where user1_.user_id=? 2021-12-09T18:39:52.900225+00:00 app[web.1]: Hibernate: select userdevice0_.user_device_id as user_dev1_8_, userdevice0_.created_at as created_2_8_, userdevice0_.updated_at as updated_3_8_, userdevice0_.device_id as device_i4_8_, userdevice0_.device_type as device_t5_8_, userdevice0_.is_refresh_active as is_refre6_8_, userdevice0_.notification_token as notifica7_8_, userdevice0_.user_id as user_id8_8_ from user_device userdevice0_ left outer join users user1_ on userdevice0_.user_id=user1_.user_id where user1_.user_id=? 2021-12-09T18:39:52.903103+00:00 app[web.1]: 21-12-09 Thu 18:39:52.902 DEBUG SQL select refreshtok0_.token_id as token_id1_4_1_, refreshtok0_.created_at as created_2_4_1_, refreshtok0_.updated_at as updated_3_4_1_, refreshtok0_.expiry_dt as expiry_d4_4_1_, refreshtok0_.refresh_count as refresh_5_4_1_, refreshtok0_.token as token6_4_1_, refreshtok0_.user_device_id as user_dev7_4_1_, userdevice1_.user_device_id as user_dev1_8_0_, userdevice1_.created_at as created_2_8_0_, userdevice1_.updated_at as updated_3_8_0_, userdevice1_.device_id as device_i4_8_0_, userdevice1_.device_type as device_t5_8_0_, userdevice1_.is_refresh_active as is_refre6_8_0_, userdevice1_.notification_token as notifica7_8_0_, userdevice1_.user_id as user_id8_8_0_ from refresh_token refreshtok0_ inner join user_device userdevice1_ on refreshtok0_.user_device_id=userdevice1_.user_device_id where refreshtok0_.user_device_id=? 2021-12-09T18:39:52.903170+00:00 app[web.1]: Hibernate: select refreshtok0_.token_id as token_id1_4_1_, refreshtok0_.created_at as created_2_4_1_, refreshtok0_.updated_at as updated_3_4_1_, refreshtok0_.expiry_dt as expiry_d4_4_1_, refreshtok0_.refresh_count as refresh_5_4_1_, refreshtok0_.token as token6_4_1_, refreshtok0_.user_device_id as user_dev7_4_1_, userdevice1_.user_device_id as user_dev1_8_0_, userdevice1_.created_at as created_2_8_0_, userdevice1_.updated_at as updated_3_8_0_, userdevice1_.device_id as device_i4_8_0_, userdevice1_.device_type as device_t5_8_0_, userdevice1_.is_refresh_active as is_refre6_8_0_, userdevice1_.notification_token as notifica7_8_0_, userdevice1_.user_id as user_id8_8_0_ from refresh_token refreshtok0_ inner join user_device userdevice1_ on refreshtok0_.user_device_id=userdevice1_.user_device_id where refreshtok0_.user_device_id=? 2021-12-09T18:39:52.905905+00:00 app[web.1]: 21-12-09 Thu 18:39:52.905 DEBUG SQL select refreshtok0_.token_id as token_id1_4_1_, refreshtok0_.created_at as created_2_4_1_, refreshtok0_.updated_at as updated_3_4_1_, refreshtok0_.expiry_dt as expiry_d4_4_1_, refreshtok0_.refresh_count as refresh_5_4_1_, refreshtok0_.token as token6_4_1_, refreshtok0_.user_device_id as user_dev7_4_1_, userdevice1_.user_device_id as user_dev1_8_0_, userdevice1_.created_at as created_2_8_0_, userdevice1_.updated_at as updated_3_8_0_, userdevice1_.device_id as device_i4_8_0_, userdevice1_.device_type as device_t5_8_0_, userdevice1_.is_refresh_active as is_refre6_8_0_, userdevice1_.notification_token as notifica7_8_0_, userdevice1_.user_id as user_id8_8_0_ from refresh_token refreshtok0_ inner join user_device userdevice1_ on refreshtok0_.user_device_id=userdevice1_.user_device_id where refreshtok0_.user_device_id=? 2021-12-09T18:39:52.905963+00:00 app[web.1]: Hibernate: select refreshtok0_.token_id as token_id1_4_1_, refreshtok0_.created_at as created_2_4_1_, refreshtok0_.updated_at as updated_3_4_1_, refreshtok0_.expiry_dt as expiry_d4_4_1_, refreshtok0_.refresh_count as refresh_5_4_1_, refreshtok0_.token as token6_4_1_, refreshtok0_.user_device_id as user_dev7_4_1_, userdevice1_.user_device_id as user_dev1_8_0_, userdevice1_.created_at as created_2_8_0_, userdevice1_.updated_at as updated_3_8_0_, userdevice1_.device_id as device_i4_8_0_, userdevice1_.device_type as device_t5_8_0_, userdevice1_.is_refresh_active as is_refre6_8_0_, userdevice1_.notification_token as notifica7_8_0_, userdevice1_.user_id as user_id8_8_0_ from refresh_token refreshtok0_ inner join user_device userdevice1_ on refreshtok0_.user_device_id=userdevice1_.user_device_id where refreshtok0_.user_device_id=? 2021-12-09T18:39:52.909292+00:00 app[web.1]: 21-12-09 Thu 18:39:52.908 ERROR ServiceAspect Exception in com.webApp.service.UserDeviceService.findByUserId() with cause = {} 2021-12-09T18:39:52.909294+00:00 app[web.1]: javax.persistence.NonUniqueResultException: query did not return a unique result: 2
And in the Heroku DB, when this happens, there just two parts fully identical data with the same user_id, which is wrong, and that’s why -> error, so again it’s not all the time, it’s time to time, but It can crash all the project, if you have any ideas why this might have happened, please share it with me.
Thanks in advance.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
It is working perfectly fine now, thanks a lot!)
@WoodySide I’ve landed #60. Can you give it a go and confirm if the fix works for you?