I'm trying to get Emails entity in one of my DAO's method by this method:
Emails mail = entityManager.find(Emails.class, email);
//test
System.out.println("code: " + code + ", email: " + email);
System.out.println(mail == null ? "mail equal null"
: ("mail:" + mail.getConfirmationCode() + ", "
+ mail.getEmail() + ", " + mail.getUser_id()));
where entityManager's find method returns null. I'm sure that both arguments of that method are proper and that row exists in my database so the method shuld return an entity, not null.
And what's important. When i'm using the same method in another method of the same DAO class with the same arguments then it works fine and entityManager's find method returns proper entity. All the methods are annotated as Transactional.
I note that when i call find method referencing to another row then it returns proper entity. The problem is only with one entity, but the same find mathod with that entity still works in anothers DAO's method.
Update: Let's say the primary key of that row is "adrian@domain.com". Then (All in the same DAO's method) when i type the PK in the second argument manually then it returns proper Entity:
Emails mailAddresse = entityManager.find(Emails.class, "adrian@domain.com");
and when i pass email instance to the method's PK argument which is "adrian@domain.com", then it returns null:
Emails mail = entityManager.find(Emails.class, email);
System.out.println("email: " + email);
In the console i can see email: "adrian@domain.com" BUT following code print in console email not equal adrian@domain.com
if("adrian@domain.com".equals(email)) System.out.println("email equal adrian@domain.com");
else System.out.println("email not equal adrian@domain.com");
When i would expect email equal adrian@domain.com. Do anybody know why?
Problem solved: The reason that find method was returning null was that i was passing an email to email variable by assuming a HTTP request parameter with double quotes, which is wrong way:
.../confirmation?email="adrian@domain.com"
and should be without any quotes, that way:
.../confirmation?email=adrian@domain.com