Issues with HashMap in Non-Persistent Objects in Mendix

0
Hello Mendix Community,   I am trying to use HashMapUtils in Mendix to store data in a non-persistent object. I can create the HashMap and access it successfully the first time, but in subsequent accesses (across different microflows using the same mapId), the map seems to be missing. Could you please advise on the correct way to bind a HashMap in a non-persistent object? Also, is there a way to check if the map has been garbage collected by the JVM?   Steps I am following: When creating a non-persistent entity Data, I create a HashMap and store its mapId as a string attribute in my non-persistent entity Data. Based on this Data, I put the required parameters into the HashMap. I then frequently try to retrieve the HashMap using this mapId and access the MendixObjects stored inside. Currently, this is where I encounter errors because the HashMap seems to disappear.   I am aware that I could use a List Operation with Find to retrieve the objects, but that approach has a time complexity of O(n). I am looking for a way to reduce the lookup time to O(1) for each access.   Thank you for your guidance!  
asked
1 answers
1

Hi Sally Peng

 

Your HashMap disappears because non‑persistent entities and their references don’t survive across microflows — the JVM garbage collects them once the request ends. To keep O(1) lookups reliable, either use a persistent entity with an indexed attribute (Mendix‑native and stable), or manage the HashMap in a session‑scoped Java cache so the JVM holds a strong reference until you clear it. If you call HashMapUtils.getMap(mapId) and get null, that means the map was already collected. For business data, persistence with indexes is best; for temporary session data, a custom cache manager is safer than relying on non‑persistent objects.

 

I hope this helps.

answered