Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366059 - Exceptions (NPE and other) during commit() or flush() when using MAP for 1:n relations
Summary: Exceptions (NPE and other) during commit() or flush() when using MAP for 1:n ...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 major with 7 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-08 11:13 EST by roman Mising name CLA
Modified: 2022-06-09 10:07 EDT (History)
2 users (show)

See Also:


Attachments
eclipse project to reproduce errors (unittests) (27.28 KB, application/x-zip-compressed)
2011-12-08 11:19 EST, roman Mising name CLA
no flags Details
same as testEclipseLinkMap but using Set for relations (27.49 KB, application/x-zip-compressed)
2011-12-08 11:20 EST, roman Mising name CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description roman Mising name CLA 2011-12-08 11:13:15 EST
Build Identifier: 20110916-0149

when using Map for 1:n relations, a lot of different errors occur on commit() (mostly, sometimes on flush()). If a flush() is added/removed/changed position, the error does not occur or another error is reported.

Most of the errors seems to relate to the caching subsystem.

more details on the forum http://www.eclipse.org/forums/index.php/mv/msg/263510/761327/#msg_761327

I will upload a test project with different unittests, that shows samples, when errors occur. In the test cases, there are comments, how to workaround the errors.

I will upload a second test project. It has the same unittests, the only difference is, that Set instead of Map is used for 1:n relations.

In this test project all unittests work.

So the errors has to be related to the implementation of the Map for relations.


Reproducible: Always

Steps to Reproduce:
run unittests of enclosed projects (against an oracle database)
Comment 1 roman Mising name CLA 2011-12-08 11:19:32 EST
Created attachment 208102 [details]
eclipse project to reproduce errors (unittests)
Comment 2 roman Mising name CLA 2011-12-08 11:20:23 EST
Created attachment 208103 [details]
same as testEclipseLinkMap but using Set for relations
Comment 3 roman Mising name CLA 2011-12-08 11:25:00 EST
disabling the shared cache helps a lot, but some errors still occur.
Comment 4 Tom Ware CLA 2011-12-22 10:37:43 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 5 Cristian Oancea CLA 2013-02-19 09:28:48 EST
in 2.4.0

for a 1-M relation using a map with table key , on remove  the SQL transaction is commited , but cache is not , a NPE is thrown

@OneToMany(fetch = FetchType.LAZY, targetEntity = Child.class,
        mappedBy = "direct", cascade = { CascadeType.REMOVE },
        orphanRemoval = true)
@MapKeyColumn(name = "child_name", table = "child", insertable = false,
        updatable = false)

@Cache(type = CacheType.HARD_WEAK, size = 10000, expiry = -1,
    alwaysRefresh = true, isolation = CacheIsolationType.SHARED,
    coordinationType = CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS)
@Cacheable(value = true)

org.eclipse.persistence.internal.queries.MapContainerPolicy

key = null 
element !=null

public boolean removeFrom(Object key, Object element, Object container, AbstractSession session) {
        try {
            Object returnValue = null;
            if (key != null) {
                returnValue = ((Map)container).remove(key);
            } else if (element != null) {
!!!!
                returnValue = ((Map)container).remove(keyFrom(element, session));
### hier comes a NullPointerException
!!!

            }
            if (returnValue == null) {
                return false;
            } else {
                return true;
            }
        } catch (UnsupportedOperationException ex) {
            throw QueryException.methodNotValid(container, "remove(Object element)");
        }
    }

the keyFrom function returns a null

org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy

public Object keyFrom(Object element, AbstractSession session) {
        // key is mapped to the database table and not the object and therefore cannot be extracted from the object
        if (keyMapping != null){
            return null;
        }
        return super.keyFrom(element, session);
    }
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:07:59 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink