You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Albert Lee (JIRA)" <ji...@apache.org> on 2010/02/11 17:18:28 UTC

[jira] Created: (OPENJPA-1506) ConfigurationImpl.equals fails using a OpenJPA derived provider

ConfigurationImpl.equals fails using a OpenJPA derived provider
---------------------------------------------------------------

                 Key: OPENJPA-1506
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1506
             Project: OpenJPA
          Issue Type: Bug
          Components: lib
    Affects Versions: 2.0.0, 2.0.1
            Reporter: Albert Lee
            Assignee: Albert Lee
            Priority: Minor
             Fix For: 2.0.0


TestDynamicConfiguration.testConfigurationIsEqualByValueAndHashCode failed with configuration object equality
using a OpenJPA derived provider.

    public void testConfigurationIsEqualByValueAndHashCode() {
		OpenJPAEntityManagerFactorySPI emf1 = createEMF(FRESH_EMF);
		assertNotNull(emf1);
		OpenJPAConfiguration conf1 = emf1.getConfiguration();
		
		OpenJPAEntityManagerFactorySPI emf2 = createEMF(FRESH_EMF);
		assertNotNull(emf2);
		OpenJPAConfiguration conf2 = emf2.getConfiguration();
		
		assertFalse(emf1==emf2);
		assertFalse(emf1.equals(emf2));
		assertFalse(conf1==conf2);
		assertEquals(conf1, conf2);	<<<< faild here
		assertEquals(conf1.hashCode(), conf2.hashCode());
        	assertEquals(conf1.toProperties(false), conf2.toProperties(false));
	}

The problem is in the equals() method of ConfigurationImpl:

    public boolean equals(Object other) {
	.....
        for(Value v : _vals) {
            Value thatV = conf.getValue(propName);
       	    if (!v.equals(thatV)) {
        	return false;
            }
        }
        return true;
    }

getValue search backward based on the property name as in:

    public Value getValue(String property) {
        if (property == null)
            return null;

        // search backwards so that custom values added after construction
        // are found quickly, since this will be the std way of accessing them
        for (int i = _vals.size()-1; i >= 0; i--) { 
            if (_vals.get(i).matches(property))
                return _vals.get(i);
        }
        return null;
    }

In the case of a dervied provider, it adds new EntityManagerFactoryValue to the end of the property list, which in theory override
the one defined by the openjpa provider.

However the equals method iterate the "current" configuration _vals list from the top but match the "other" configuration _vals
list found from the bottom, so even both configuration objects are exactly the same, the equals will fail.

In the case of a single openjpa provider, this problem is NOT surfaced.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (OPENJPA-1506) ConfigurationImpl.equals fails using a OpenJPA derived provider

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1506?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Albert Lee closed OPENJPA-1506.
-------------------------------


> ConfigurationImpl.equals fails using a OpenJPA derived provider
> ---------------------------------------------------------------
>
>                 Key: OPENJPA-1506
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1506
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>    Affects Versions: 2.0.0, 2.0.1
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>            Priority: Minor
>             Fix For: 2.0.0-beta2, 2.0.0
>
>
> TestDynamicConfiguration.testConfigurationIsEqualByValueAndHashCode failed with configuration object equality
> using a OpenJPA derived provider.
>     public void testConfigurationIsEqualByValueAndHashCode() {
> 		OpenJPAEntityManagerFactorySPI emf1 = createEMF(FRESH_EMF);
> 		assertNotNull(emf1);
> 		OpenJPAConfiguration conf1 = emf1.getConfiguration();
> 		
> 		OpenJPAEntityManagerFactorySPI emf2 = createEMF(FRESH_EMF);
> 		assertNotNull(emf2);
> 		OpenJPAConfiguration conf2 = emf2.getConfiguration();
> 		
> 		assertFalse(emf1==emf2);
> 		assertFalse(emf1.equals(emf2));
> 		assertFalse(conf1==conf2);
> 		assertEquals(conf1, conf2);	<<<< faild here
> 		assertEquals(conf1.hashCode(), conf2.hashCode());
>         	assertEquals(conf1.toProperties(false), conf2.toProperties(false));
> 	}
> The problem is in the equals() method of ConfigurationImpl:
>     public boolean equals(Object other) {
> 	.....
>         for(Value v : _vals) {
>             Value thatV = conf.getValue(propName);
>        	    if (!v.equals(thatV)) {
>         	return false;
>             }
>         }
>         return true;
>     }
> getValue search backward based on the property name as in:
>     public Value getValue(String property) {
>         if (property == null)
>             return null;
>         // search backwards so that custom values added after construction
>         // are found quickly, since this will be the std way of accessing them
>         for (int i = _vals.size()-1; i >= 0; i--) { 
>             if (_vals.get(i).matches(property))
>                 return _vals.get(i);
>         }
>         return null;
>     }
> In the case of a dervied provider, it adds new EntityManagerFactoryValue to the end of the property list, which in theory override
> the one defined by the openjpa provider.
> However the equals method iterate the "current" configuration _vals list from the top but match the "other" configuration _vals
> list found from the bottom, so even both configuration objects are exactly the same, the equals will fail.
> In the case of a single openjpa provider, this problem is NOT surfaced.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1506) ConfigurationImpl.equals fails using a OpenJPA derived provider

Posted by "Donald Woods (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1506?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Donald Woods updated OPENJPA-1506:
----------------------------------

    Affects Version/s:     (was: 2.0.1)
                           (was: 2.0.0)
                       2.0.0-beta2
        Fix Version/s:     (was: 2.0.0-beta2)
                           (was: 2.0.0)
                       2.0.0-beta3

> ConfigurationImpl.equals fails using a OpenJPA derived provider
> ---------------------------------------------------------------
>
>                 Key: OPENJPA-1506
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1506
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>    Affects Versions: 2.0.0-beta2
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>            Priority: Minor
>             Fix For: 2.0.0-beta3
>
>
> TestDynamicConfiguration.testConfigurationIsEqualByValueAndHashCode failed with configuration object equality
> using a OpenJPA derived provider.
>     public void testConfigurationIsEqualByValueAndHashCode() {
> 		OpenJPAEntityManagerFactorySPI emf1 = createEMF(FRESH_EMF);
> 		assertNotNull(emf1);
> 		OpenJPAConfiguration conf1 = emf1.getConfiguration();
> 		
> 		OpenJPAEntityManagerFactorySPI emf2 = createEMF(FRESH_EMF);
> 		assertNotNull(emf2);
> 		OpenJPAConfiguration conf2 = emf2.getConfiguration();
> 		
> 		assertFalse(emf1==emf2);
> 		assertFalse(emf1.equals(emf2));
> 		assertFalse(conf1==conf2);
> 		assertEquals(conf1, conf2);	<<<< faild here
> 		assertEquals(conf1.hashCode(), conf2.hashCode());
>         	assertEquals(conf1.toProperties(false), conf2.toProperties(false));
> 	}
> The problem is in the equals() method of ConfigurationImpl:
>     public boolean equals(Object other) {
> 	.....
>         for(Value v : _vals) {
>             Value thatV = conf.getValue(propName);
>        	    if (!v.equals(thatV)) {
>         	return false;
>             }
>         }
>         return true;
>     }
> getValue search backward based on the property name as in:
>     public Value getValue(String property) {
>         if (property == null)
>             return null;
>         // search backwards so that custom values added after construction
>         // are found quickly, since this will be the std way of accessing them
>         for (int i = _vals.size()-1; i >= 0; i--) { 
>             if (_vals.get(i).matches(property))
>                 return _vals.get(i);
>         }
>         return null;
>     }
> In the case of a dervied provider, it adds new EntityManagerFactoryValue to the end of the property list, which in theory override
> the one defined by the openjpa provider.
> However the equals method iterate the "current" configuration _vals list from the top but match the "other" configuration _vals
> list found from the bottom, so even both configuration objects are exactly the same, the equals will fail.
> In the case of a single openjpa provider, this problem is NOT surfaced.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-1506) ConfigurationImpl.equals fails using a OpenJPA derived provider

Posted by "Albert Lee (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1506?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Albert Lee resolved OPENJPA-1506.
---------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0.0-beta2

> ConfigurationImpl.equals fails using a OpenJPA derived provider
> ---------------------------------------------------------------
>
>                 Key: OPENJPA-1506
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1506
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>    Affects Versions: 2.0.0, 2.0.1
>            Reporter: Albert Lee
>            Assignee: Albert Lee
>            Priority: Minor
>             Fix For: 2.0.0, 2.0.0-beta2
>
>
> TestDynamicConfiguration.testConfigurationIsEqualByValueAndHashCode failed with configuration object equality
> using a OpenJPA derived provider.
>     public void testConfigurationIsEqualByValueAndHashCode() {
> 		OpenJPAEntityManagerFactorySPI emf1 = createEMF(FRESH_EMF);
> 		assertNotNull(emf1);
> 		OpenJPAConfiguration conf1 = emf1.getConfiguration();
> 		
> 		OpenJPAEntityManagerFactorySPI emf2 = createEMF(FRESH_EMF);
> 		assertNotNull(emf2);
> 		OpenJPAConfiguration conf2 = emf2.getConfiguration();
> 		
> 		assertFalse(emf1==emf2);
> 		assertFalse(emf1.equals(emf2));
> 		assertFalse(conf1==conf2);
> 		assertEquals(conf1, conf2);	<<<< faild here
> 		assertEquals(conf1.hashCode(), conf2.hashCode());
>         	assertEquals(conf1.toProperties(false), conf2.toProperties(false));
> 	}
> The problem is in the equals() method of ConfigurationImpl:
>     public boolean equals(Object other) {
> 	.....
>         for(Value v : _vals) {
>             Value thatV = conf.getValue(propName);
>        	    if (!v.equals(thatV)) {
>         	return false;
>             }
>         }
>         return true;
>     }
> getValue search backward based on the property name as in:
>     public Value getValue(String property) {
>         if (property == null)
>             return null;
>         // search backwards so that custom values added after construction
>         // are found quickly, since this will be the std way of accessing them
>         for (int i = _vals.size()-1; i >= 0; i--) { 
>             if (_vals.get(i).matches(property))
>                 return _vals.get(i);
>         }
>         return null;
>     }
> In the case of a dervied provider, it adds new EntityManagerFactoryValue to the end of the property list, which in theory override
> the one defined by the openjpa provider.
> However the equals method iterate the "current" configuration _vals list from the top but match the "other" configuration _vals
> list found from the bottom, so even both configuration objects are exactly the same, the equals will fail.
> In the case of a single openjpa provider, this problem is NOT surfaced.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.