Search code examples
javatalend

Talend - cannot use globalMap.get() in tmap


I have tried every possible combination in my tmap, and I am frustrated beyond belief

i set my global variable in a tJava like so

globalMap.put("table_id",22);

then later down the component line I call the global map in the out schema of a tMapenter image description here

globalMap.get("table_id");

and get the following error

Error Line: 2539
Detail Message: Type mismatch: cannot convert from Object to int
There may be some other errors caused by JVM compatibility. Make sure your JVM setup is similar to the studio.

thins I have tried

(Integer)globalMap.get("table_id")   
((Integer)globalMap.get("table_id"))   
Integer.parseint(globalMap.get("table_id"))

any combination will not work, but simply putting the number 22 will work

any help would be extremely helpful


Solution

  • The answer lies in this statement:

    Type mismatch: cannot convert from Object to int

    So, it is definitely a Casting issue. I know for sure that : (Integer)globalMap.get("table_id") should work!

    If it doesn't work, the error message will certainly be different than "Type mismatch"!

    • note 1: it would better to use the native component "tSetGlobalVar" to store a value in the globalMap.

    • note 2: context variables should not be modified dynamically in Runtime, because they are not thread-safe (globalMap is!).