Hi everybody,
I have an embeddable class named Sci with 4 String fields, embedded in a Creditor entity.
When I try to find a Creditor using a full Sci object, everything works fine.
Code:
Sci sci = new Sci("FR","98","ZZZ","0123456");
Creditor creditor = new Creditor();
creditor.setSci(sci);
entityManager.persist(creditor);
TypedQuery<Creditor> q = entityManager.createQuery("from Creditor c where c.sci=:sci", Creditor.class);
q.setParameter("sci", sci);
Creditor creditorFromDb = q.getSingleResult();
Assert.assertNotNull("Could not retrieve creditor after insert", creditorFromDb);
But when one of Sci fields is null, the test fails :
Code:
Sci sci = new Sci("FR","98",null,"0123456");
Creditor creditor = new Creditor();
creditor.setSci(sci);
entityManager.persist(creditor);
TypedQuery<Creditor> q = entityManager.createQuery("from Creditor c where c.sci=:sci", Creditor.class);
q.setParameter("sci", sci);
Creditor creditorFromDb = q.getSingleResult();
Assert.assertNotNull("Could not retrieve creditor after insert", creditorFromDb);
If I dump requests on my mysql server, I can see generated request is :
Code:
select [...] from Creditor creditor0_ where (creditor0_.sci_businesscode, creditor0_.sci_checkdigit, creditor0_.sci_countryiso, creditor0_.sci_nationalidentifier)=(null, '98', 'FR', '0123456') limit 2
The problem comes from '=' operator with null value. It think it should be something like :
Code:
creditor0_.sci_businesscode is null
Is this a normal behavior or a bug ? I cant find anything relevant in JPA specs about this point.
Regards,
Johann