diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java index 61d2839c8..e75aa0bae 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/Employee.java @@ -78,4 +78,26 @@ public class Employee { } return true; } + + /* + * The following change is for the comparison of Date object. In MySQL, + * "microseconds cannot be stored into a column of any temporal data type. + * Any microseconds part is discarded. " (http://dev.mysql.com/doc/refman/5.1/en/datetime.html). + * As a result, when the value retrieved from the database will be different from the + * original value in the memory for the loss of microsecond. The fix is to call toString + * (which will strip the microseconds0 on the Date object and compare the String values. + */ + + public static Employee findEmpl(Map map, EmployeePK key) { + String name = key.getName(); + String bDateStr = key.getBDay().toString(); + Set keys = map.keySet(); + for (EmployeePK thisKey : keys) { + if (name.equals(thisKey.getName()) && + bDateStr.equals(thisKey.getBDay().toString())) { + return map.get(thisKey); + } + } + return null; + } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java index 2b648dd68..aed9bdd40 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/EmployeePK.java @@ -49,7 +49,7 @@ public class EmployeePK implements Serializable { return false; EmployeePK pk = (EmployeePK) o; if (pk.name.equals(name) && - pk.bDay.equals(bDay)) + pk.bDay.toString().equals(bDay.toString())) return true; return false; } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java index d1d9808f8..e69dedf50 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/PhoneNumber.java @@ -70,11 +70,15 @@ public class PhoneNumber { (Collection>) emps.entrySet(); for (Map.Entry entry : entries) { EmployeePK key = entry.getKey(); - Employee e0 = map.get(key); - Employee e = emps.get(key); + Employee e0 = Employee.findEmpl(map, key); + Employee e = Employee.findEmpl(emps, key); + if ((e == null && e0 != null) || (e != null && e0 == null)) + return false; if (!e.getEmpPK().equals(e0.getEmpPK())) return false; } return true; } + + } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java index 7c794b1ef..63641ff1a 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java @@ -46,8 +46,8 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase { public List empPKs = new ArrayList(); public List phonePKs = new ArrayList(); - public Map empMap = - new HashMap(); + public Map empMap = + new HashMap(); public Map phoneMap = new HashMap(); @@ -190,7 +190,7 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase { EntityTransaction tran = em.getTransaction(); for (int i = 0; i < numEmployees; i++) { Employee e = createEmployee(em, empId++); - empMap.put(e.getEmpPK(), e); + empMap.put(e.getEmpPK().getName(), e); } tran.begin(); em.flush(); @@ -200,7 +200,8 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase { public Employee createEmployee(EntityManager em, int id) { Employee e = new Employee(); - EmployeePK empPK = new EmployeePK("e" + id, new Date()); + Date bDay = new Date(System.currentTimeMillis() - 1000000); + EmployeePK empPK = new EmployeePK("e" + id, bDay); empPKs.add(empPK); e.setEmpPK(empPK); e.setSalary(1000); @@ -264,7 +265,7 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase { public void assertEmployee(Employee e) throws Exception { EmployeePK empPK = e.getEmpPK(); - Employee e0 = empMap.get(empPK); + Employee e0 = empMap.get(empPK.getName()); Map phones = e.getPhoneNumbers(); Map phones0 = e0.getPhoneNumbers(); Assert.assertEquals(phones0.size(), phones.size()); @@ -300,7 +301,8 @@ public class TestMany2ManyMapEx10 extends SQLListenerTestCase { for (Map.Entry entry0 : entrySets0) { EmployeePK key0 = entry0.getKey(); Employee e0 = entry0.getValue(); - Employee e = es.get(key0); + //Employee e = es.get(key0); + Employee e = Employee.findEmpl(es, key0); if (!e0.equals(e)) throw new Exception("Assertion failure"); } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java index c717feada..e4b2ee165 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestMultipleEntityProjection.java @@ -85,7 +85,7 @@ public class TestMultipleEntityProjection extends SingleEMFTestCase { } catch (ParseException e) { mag.setDatePublished(null); } - mag.setTsPublished(new Timestamp(System.currentTimeMillis())); + mag.setTsPublished(new Timestamp(System.currentTimeMillis() - 100000)); em.persist(pub); }