question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

javax.persistence.NonUniqueResultException: query did not return a unique result: 2 (this error happens only through Heroku server-free option)

See original GitHub issue

When 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:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
WoodySidecommented, Dec 19, 2021

@WoodySide I’ve landed #60. Can you give it a go and confirm if the fix works for you?

It is working perfectly fine now, thanks a lot!)

0reactions
isopropylcyanidecommented, Dec 18, 2021

@WoodySide I’ve landed #60. Can you give it a go and confirm if the fix works for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - org.hibernate.NonUniqueResultException: query did not ...
In API Docs uniqueResult() method says that Convenience method to return a single instance that matches the query, or null if the query...
Read more >
query did not return a unique result: 2 (APNX-1-4071-007)
Facing an error while deploying a Site, any idea on the root cause and fix? Deploy Log: Status: Failed. Current step: Importing Application....
Read more >
Help on javax.persistence.NonUniqueResultException
Hi all, Im developing and EJB 3.0 application with JBOSS 4.0.4. ... NonUniqueResultException: query did not return a unique result: 161 at ...
Read more >
Issues · isopropylcyanide/Jwt-Spring-Security-JPA · GitHub
NonUniqueResultException: query did not return a unique result: 2 (this error happens only through Heroku server-free option) bug Something isn't working.
Read more >
Java – org.hibernate.NonUniqueResultException: query did ...
NonUniqueResultException : query did not return a unique result: 2. daohibernatehqljavajpql. I have below code in my DAO: String sql = "SELECT COUNT(*)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found