java - EntityManager find method with proper arguments returns null -
i'm trying emails entity in 1 of dao's method 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 both arguments of method proper , row exists in database method shuld return entity, not null.
and what's important. when i'm using same method in method of same dao class same arguments works fine , entitymanager's find method returns proper entity. methods annotated transactional.
i note when call find method referencing row returns proper entity. problem 1 entity, same find mathod entity still works in anothers dao's method.
update: let's primary key of row "adrian@domain.com". (all in same dao's method) when type pk in second argument manually returns proper entity:
emails mailaddresse = entitymanager.find(emails.class, "adrian@domain.com");
and when pass email instance method's pk argument "adrian@domain.com", returns null:
emails mail = entitymanager.find(emails.class, email); system.out.println("email: " + email);
in console 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 expect email equal adrian@domain.com. know why?
problem solved: reason find method returning null was passing email email variable assuming http request parameter double quotes, wrong way:
.../confirmation?email="adrian@domain.com"
and should be without quotes, way:
.../confirmation?email=adrian@domain.com
Comments
Post a Comment