[resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

One Star

[resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

Hi All,
I have two jobs called parent and child job.parent job will call child job and child job will return some result to parent job.
Parent and child jobs will look like below :
tjava :


tFixedFlowInput schema :

tBufferOutput schema :



Child job :


Parent job :


tRunJob Schema:


tJavaRow will looks like below :


But when I execute the parent job I'm getting an exception like tBufferOutput:java.util.HashMap cannot be cast to java.lang.String.Am I doing something wrong? Is there any other alternative way to return childjob result to the parent job?
Can any one please advice me on this.


Thanks in advance,
Sayagoud Ravelly

Accepted Solutions
One Star

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

Hi All,
I resolved this issue in following way :
Parent job :we need to define a ConcurrentHashMap in parent job
globalMap.put("sharedMap", new java.util.concurrent.ConcurrentHashMap());
Child job : Define a context variable of type object here for ex:sharedMap
((java.util.Map)context.sharedMap).put("test", "test123");
((java.util.Map)context.sharedMap).put("hello","hello123");
Configure tRunjob in parent job like below :

Retrieve the values in Parent job like below:
System.out.println("test>>"+((java.util.Map)globalMap.get("sharedMap")).get("test"));
 
System.out.println("hello>>"+((java.util.Map)globalMap.get("sharedMap")).get("hello"));
output :


All Replies
Seventeen Stars

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

You have misunderstood the Talend type List. List means a couple of Strings which can be selected in a combobox (e.g. for a prompt). Use the Talend type Object.
One Star

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

You have misunderstood the Talend type List. List means a couple of Strings which can be selected in a combobox (e.g. for a prompt). Use the Talend type Object.

Hi jlolling,
Thanks for your reply.I have tried the way you suggested but got a similar exception like below in parent job.

Seventeen Stars

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

You have to change the type for the context variable in both jobs (parent and child).
One Star

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

You have to change the type for the context variable in both jobs (parent and child).

Hi jlolling,
I configured the context variable in child job as of type Object.

But in Parent job I'm using input_row.ListObject directly from the trunjob flow like below.
 List<HashMap<String,HashMap<String, String>>> childjob_list = (List<HashMap<String,HashMap<String, String>>>)input_row.ListObject;
And also tried by defining the same context in parent job like below but no luck,getting same exception.


List<HashMap<String,HashMap<String, String>>> childjob_list = (List<HashMap<String,HashMap<String, String>>>)input_row.ListObject;
One Star

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

Hi All,
I resolved this issue in following way :
Parent job :we need to define a ConcurrentHashMap in parent job
globalMap.put("sharedMap", new java.util.concurrent.ConcurrentHashMap());
Child job : Define a context variable of type object here for ex:sharedMap
((java.util.Map)context.sharedMap).put("test", "test123");
((java.util.Map)context.sharedMap).put("hello","hello123");
Configure tRunjob in parent job like below :

Retrieve the values in Parent job like below:
System.out.println("test>>"+((java.util.Map)globalMap.get("sharedMap")).get("test"));
 
System.out.println("hello>>"+((java.util.Map)globalMap.get("sharedMap")).get("hello"));
output :

One Star

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

Attempting to follow this recipe to draw out the context titled "Failed_Dir" from the sub-job.
I put in "sharedMap" as a context variable with the type as Object.
tjava2 --> tRunJob1 --> tJava3
1) tJava2 - globalMap.put("sharedMap", new java.util.concurrent.ConcurrentHashMap());
2a) tRunJob1 - Setting as sharedMap and Value: (java.util.Map)globalMap.get("sharedMap")
2b) tjava 1 inside the Child Job - ((java.util.Map) context.sharedMap).put("Failed_Dir", context.Failed_Dir);
3) tjava3 - System.out.println("Failed_Dir=" + ((String) ((java.util.Map) globalMap.get("sharedMap")).get("Failed_Dir")));

What I'm getting is:
connecting to socket on port 3485
connected
Exception in component tJava_3
java.lang.NullPointerException
    at spv.jo_spv_0010_ingestpolicyenginedata_02_new_0_2.jo_SPV_0010_IngestPolicyEngineData_02_NEW.tJava_2Process(jo_SPV_0010_IngestPolicyEngineData_02_NEW.java:3218)
    at spv.jo_spv_0010_ingestpolicyenginedata_02_new_0_2.jo_SPV_0010_IngestPolicyEngineData_02_NEW.runJobInTOS(jo_SPV_0010_IngestPolicyEngineData_02_NEW.java:4549)
    at spv.jo_spv_0010_ingestpolicyenginedata_02_new_0_2.jo_SPV_0010_IngestPolicyEngineData_02_NEW.main(jo_SPV_0010_IngestPolicyEngineData_02_NEW.java:3791)
disconnected
Job jo_SPV_0010_IngestPolicyEngineData_02_NEW ended at 17:29 14/09/2016.
Can anybody help?
One Star

Re: [resolved] tBufferOutput:java.util.HashMap cannot be cast to java.lang.String

Just bumping this up so if anyone has any ideas?
Or should I put this as a new topic?