Jay Rizzi
Jay Rizzi

Reputation: 4304

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

Upvotes: 0

Views: 10442

Answers (3)

Jay Rizzi
Jay Rizzi

Reputation: 4304

i agree with @mhassine that (Integer)globalMap.get("table_id") should work, but i only got it to work with

(int)globalMap.get("table_id")

maybe this is a quirk with 6.3, but yea cant explain it

Upvotes: 0

mhassine
mhassine

Reputation: 191

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!).

Upvotes: 2

user1645603
user1645603

Reputation: 1

You can use context variable instead.

Step 1. Declare the variable in Context.

Step 2. Assign the variable where you are assigning the value. e.g. context.table_id=22;

step 3. use this context variable in tMap component.

Upvotes: 0

Related Questions