I hit a problem when writing tests for a database application using JPA2 and EclipseLink:
I add some entity to a database, retrieve it later and want to compare it to an instance which has the values I expect to confirm that the addition worked as I intended.
First I wrote something like
assertEquals(expResult, dbResult);
which failed, because I can't really know the value of id field, which is generated by the database and therefore dbResult differs from expResult which I created with new and populated manually.
I see two options:
- Either I remove the - idfield from- equalsand- hashCodeso that the comparison is only based on the "real values". I don't know if this causes problems in the database or elsewhere, though.
- Or I write my tests to explicitly check every field except - idmanually.
What should I do?
 
     
     
     
    