Hibernate 4 : setting a default value if query returns null - spring

I have a use case where i am mapping two tables to the same object.
In this object i have a string called source and I want to be able to set the table name or the database name to this variable.
Any ideas on how to achieve this?
I have thought about iterating over my list and manually setting it but this has the potential to waste a fair chunk of time.
I appreciate this is somewhat of an odd request so this may be the only way but am hoping for a solution that maps the source variable when hibernate is mapping everything else.

if i had understood correctly your issue , then your solution might be the MappedSuperClass , in which you must have an abstract class , which will have the common fields of the two tables and then you will extend that to the two entities you want , which will point to two different tables.
Check this link

You could try to achieve this with Load listener or Interceptors. In the listener/interceptor you can check what the data source is and populate the source field accordingly.

In the end i ended up using a formula to map my variable to a select statement which was sufficient for what i needed.

Related

Informatica routers

I have two sources A source B
Source A passes through a drug lookup and a router to see if the NDC is present and if not goes to either a present table or a nonpresent table.
Source B does the same but only looks for GCN number if it is present then it goes to a GCN present table or a gcn not present table.
I am currently using in Group filters
ISNULL(NDC_DRUG_CODE_LOOKUP)
NOT ISNULL(NDC_DRUG_CODE_LOOKUP)
ISNULL (GCN_CODE_out_LKP)
NOT ISNULL(GCN_CODE_out_LKP)
the problem is that when the lookup and GCN or NDC code match it's not routing properly
So my question is should I use two different sorters or is there a better way to code this.
Using multiple sorters is not the right option because it reduces the performance. Not sure exactly about your requirement, but I hope below is what you are expecting. Use the condition in router in such a way,
ISNULL(NDC_DRUG_CODE_LOOKUP) AND
NOT ISNULL(NDC_DRUG_CODE_LOOKUP) AND
ISNULL (GCN_CODE_out_LKP) AND
NOT ISNULL(GCN_CODE_out_LKP)
If the condition is not working the issue would be with your lookup. Try creating an output target for each look up and test the scenario.
Try Using Unconnected lookup , Call twice with GCN and NDC , And create four flags in single router and route them as per your requirement ...And one more suggestion if you are using ISNULL in router or any transformation , try to default to some like nvl in oracle, the reason is sometime it takes null both side it does not match..
Hope this helps...

Informatica cloud: use field in pre/post sql commands

I am trying to delete a set of data in the target table based on a column (year) from the lookup in IICS (Informatica Cloud).
I want to solve this problem using pre/post sql commands but the constraint is I can't pass year column to my query.
I tried this:
delete from sample_db.tbl_emp where emp_year = {year}
I want to delete all the employees in a specific year i get from lookup return
For Ex:
I got year as '2019', all the records in table sample_db.tbl_emp containing emp_year=2019 must be deleted.
I am not sure how this works in informatica cloud.
Any leads would be helpful.
How are you getting the year value? A pre/post SQL may not be the way to go unless you need to do this as part of another transformation, i.e., before or after the transformation runs. Also, does your org only have ICDI, or also ICAI? ICAI may be a better solution depending on the value is being provided.
The following steps would help you achieve this.
Create an input-output parameter in your mapping.
Assign the result of your lookup in an expression transformation to the parameter using SetMaxVariable
Use the parameter in your target pre SQL as
delete from sample_db.tbl_emp where emp_year = $$parameter
Let me know if you have any further questions

Field order between Source and Source Qualifier need to be same?

This is might be a basic question but just curious to know, My source is a flat file and do we need to maintain same field order between source and source qualifier objects in Informaitca?
Thanks!
No but you need to maintain field order against list of fields returned by the query... especially if you use an sql override
No, you should not.You even may need to change this order if you are going to Sort data by Source Qualifier. If you set integer value for ‘Number of Sorted Ports’ SQ property Informatica Information Service(IS) will look at that number of ports starting at the top. So, you may need to rearrange ports order by moving sorting ports at top.

Qlikview: Matching columns of two indirectly link tables does not work

Following is the data model of the dashboard I am facing problem in:
http://blob:http://stackoverflow.com/f3e40cfe-e009-4d03-bcf5-b7b4305c18c4
Now, what i want to achieve is that in Case there is a filed named Manufacturing_Date. And in MWODefetcs there is a field named Defect_Date. What i want is that when ever a record is selected from a table containing cases from Case corresponding records are shown in another table based on the exact match of Manufacturing_Date=Defect_Date.
As simple as it sounds, i can not seem to accomplish it. I have tried the following expressions to no avail:
Count({<[Defect_Date_text]=p([Manu_text]),FaultID=,DEFECT_CODE=>}MFG_BARCODE_NUM)
sum({$<Defect_Date ={"=$(Manufacturing_Date__c)"}>}Defect_Date)
Do the 2 tables need to be directly linked. Is it the intermediary iFaults table that is preventing me to accomplish it?
Please help.
you should use the P() set expression like this:
sum({$<Defect_Date =P(Manufacturing_Date__c) >}Defect_Date)

iterating over linq entity column

i need to insert a record with linq
i have a namevaluecollection with the data from a form post..
so started in the name=value&name2=value2 etc.. type format
thing is i need to inset all these values into the table, but of course the table fields are typed, and i need to type up the data before inserting it
i could of course explicitly do
linqtableobj.columnproperty = convert.toWhatever(value);
but i have many columns in the table, and the data coming back from the form, doesnt always contain all fields in the table
thought i could iterate over the linq objects columns, getting their datatype - to use to convert the appropriate value from the form data
fine all good, but then im still stuck with doing
linqtableobj.columnproterty = converted value
...if there is one for every column in the table
foreach(col in newlinqrowobj)
{
newlinqobj[col] = convert.changetype(namevaluecollection[col.name],col.datatype)
}
clearly i cant do that, but anything like that possible.. or
is it possible to loop around the columns for the new 'record' setting the values as i go.. and i guess grabbing the types at that point to do the conversion
stumped i am
thanks
nat
If you have some data type with a hundred different properties, and you want to copy those into a completely different data type with a hundred different properties, then somehow somewhere in your code you are going to have to define a hundred different "mapping" instructions. It doesn't matter what framework you are using, or whether the "mapping" instructions are lines of C# code, XML elements, lambda functions, proprietary "stuff", or whatever. There's no getting away from it.
Bearing that in mind, having one line of code per property looks to me like the fastest, simplest, most readable and maintainable solution.
If I understood your problem correctly, you could use reflection (or dynamic code generation if it is performance sensitive) to circumvent your typing problems
There is a preety good description of how to do something like this at codeproject.
Basically you get a PropertyInfo for the property you want to set (if it's not a property I think you would need dynamic code generation) and use it's setValue method (after calling the appropriate Convert.ChangeType of course). This will basicall circumvent the whole static typing, so there you are.

Resources