Mapping an object using values from multiple tables
Is it possible to use values looked up in other tables when mapping an object?
For example: I have three tables. In table 1, I have fields for 'cityCode' and 'stateCode'. Table 2 is a state table which contains a list of stateCodes and corresponding stateIds. Table 3 is a city table with cityCodes listed by stateId (the city code is unique within the stateId but can be duplicated under other stateIds). Table 3 also contains the cityName for the matching cityCode/stateId pair.
I am ultimately trying to match a cityName to a cityCode. I can't figure out how to tell toplink use the stateId returned when mapping Table 1 to Table 2 via stateCode when mapping cityCode in Table 1 to Table 3.
Any help is greatly appreciated
--matt
What does your object model look like, do you have a single object with data from all three tables in it?
<p>
In general because the cardinality of the tables and usage does not match, I would not recommend using multiple tables to map this. Instead define a CityNameManager class that preloads and stores all of the city names for each state, (possible lazy initializing each set of cities per state). Your getCityName() method in your class would then just use this manager.
<p>
You could map the multiple tables but it may be difficult, and would most likely need to be read-only because I don't think you want to insert into the table2 or 3. You basically have a foreign key table1.stateCode => table2.stateCode, (table1.cityCode, table2.stateId) => (table3.cityCode, table3.stateId). You probably cannot define this in the Mapping Workbench, so would need to use the ClassDescriptor code API and an amendment method. If you can't get the foreign keys to work you can always use the descriptor multipleTableJoinExpression and define the join directly.
<p>
You could also define a OneToOneMapping to the CityName from your object using the cityCode and using a selectionCriteria() on your mapping to provide an expression that uses the getTable() method to join to the intermediate table.
<p>
<p>---
<p>James Sutherland
Similar Messages
-
Sample PHP Service selecting from multiple tables
Hi all!
I have the following challange:
How do I properly set up my PHP-service to insert, select, update and delete values from multiple tables?
So far, the standard templates generated by Flash Builder is based on a single table.
Example: I have 2 tables: [person] and [school]
[person] has [person_id, first_name, last_name, birthdate]
[school] has [school_id, person_id, school_name, city]
One [person] can have multiple [schools]
How should I define the selectByID function in PHP to be able to have
First name: [TextInput /]
Last name: [TextInput /]
Birthdate: [DateField /]
Schools:
[TabBar: School1, School2, School3 /]
[ViewStack1]
School name: [TextInput /]
Location name: [TextInput /]
[/ViewStack1]]
[ViewStack2]
School name: [TextInput /]
Location name: [TextInput /]
[/ViewStack2]]
[ViewStack3]
School name: [TextInput /]
Location name: [TextInput /]
[/ViewStack3]]
And even more interesting: How do I update all these fields back to the database?First, the relationship between school and person is many-to-many NOT one-to-many -- you will need to add a junction table.
From the form you have given I would handle insertions like this:
loop through all the schools and see if the school already exist in the DB. If so, then store the school_id. If not, then create a new record and store the id. You should have an array collection of store_ids by the end of the loop
Check whether the student exists w/in the DB. If so, then you might consider aborting the operation or you could opt to do an update. If the student doesn't exist, then create a new student record and store the new student_id (mysql::insert_id)
Loop through the school_id array and add new student_id/school_id records into the junction table.
Retrieving records is much simpler -- it's just a join on the tables i.e. "SELECT * FROM student INNER JOIN school_student ON student.student_id = school_student.student_id INNER JOIN schools ON school_student.school_id = school.school_id WHERE student.first_name = 'John' AND student.last_name = 'Doe' (assuming there aren't more than one John Does of course!).
- e -
Create object type from multiple tables for select statement
Hi there,
I have 3 tables as given below and I wish to create an object type to group selected columns as 'attribute' from multiple tables.
I need to create 2 input parameters to pass in - 'attribute' and 'attribute value' in PL/SQL and these 2 parameters will be
passing in with 'column name' and 'column value'. e.g. 'configuration' - the column name, 'eval' - the column value.
Then, the PL/SQL will execute the select statement with the column and column value provided to output the record.
Pls advise and thank you.
table ccitemnumber
name null type
ccitemnumber not null varchar2(20)
configuration varchar2(20)
item_type varchar2(30)
table productmodel
productmodelnumber not null varchar2(6)
description varchar2(60)
accesstimems number
numberofheads varchar2(2)
generation varchar2(10)
numberofdiscs varchar2(2)
factoryapplication varchar2(150)
table topmodel
stmodelnumber not null varchar2(30)
productfamily varchar2(60
formfactor varchar2(10)
modelheight varchar2(10)
formattedcapacity number
formattedcapacity_uom varchar2(20)
object type in database
configuration varchar2(20)
item_type varchar2(30)
numberofheads varchar2(2)
generation varchar2(10)
numberofdiscs varchar2(2)
factoryapplication varchar2(150)
modelheight varchar2(10)
formattedcapacity number
formattedcapacuser12043838 wrote:
Reason to do this as these fields are required to be grouped together as they are created in different tables. They are treated as 'attribute' (consists of many columns) of the part number. So, the PL/SQL is requested to design in a way able for user to pass in the column name and column value or part number, then the select statement should be able to query for the records. Another reason is a new column can be added easily without keep modifying those effected programs. Reuseable too.This basically equates to ... hard to code, hard to maintain, and poor performance.
Are you really sure you want to do this? This isn't going to be easy-street as you seem to think it is, but it's a one way street to a poorly performing system with security vulnerabilities (google SQL Injection).
I would highly recommend you reconsider your design decision here. -
From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?
Hi,
Use NVL or COALESCE:
NVL (col_a, col_b)
Returns col_a if col_a is not NULL; otherwise, it returns col_b.
Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
How to get string value from database table using Visual Studio 2005?
Hi,
Im developing plugin in illustrator cs3 using visual studio 2005. I need to get the values eneterd in database. Im able to get the integer values. But while getting string values it is returning empty value.
Im using the below code to get the values from database table
bool Table::Get(char* FieldName,int& FieldValue)
try
_variant_t vtValue;
vtValue = m_Rec->Fields->GetItem(FieldName)->GetValue();
FieldValue=vtValue.intVal;
CATCHERRGET
sprintf(m_ErrStr,"Success");
return 1;
Im using the below code to get the values.
AIErr getProjects()
char buf[5000];
int i;
std::string catName;
::CoInitialize(NULL);
Database db;
Table tbl;
errno_t err;
err = fopen(&file,"c:\\DBResult.txt","w");
fprintf(file, "Before Connection Established\n");
//MessageBox(NULL,CnnStr,"Connection String",0);
if(!db.Open(g->username,g->password,CnnStr))
db.GetErrorErrStr(ErrStr);
fprintf(file,"Error: %s\n",ErrStr);
fprintf(file, "After Connection Established\n");
if(!db.Execute("select ProjectID,ProjectName from projectsample",tbl))
db.GetErrorErrStr(ErrStr);
fprintf(file,"Error: %s\n",ErrStr);
int ProjectID;
int UserID;
int ProjectTitle;
char ProjectName[ProjectNameSize];
if(!tbl.ISEOF())
tbl.MoveFirst();
ProjectArrCnt=0;
for(i=0;i<128;i++)
buf[i]='\0';
int j=0;
while(!tbl.ISEOF())
if(tbl.Get("ProjectID",ProjectID))
fprintf(file,"Project ID: %d ",ProjectID);
ProjectInfo[ProjectArrCnt].ProjectID = ProjectID;
sprintf(buf,"%d",ProjectID);
//MessageBox(NULL, buf,"f ID", 0);
j++;
else
tbl.GetErrorErrStr(ErrStr);
fprintf(file,"Error: %s\n",ErrStr);
break;
//if(tbl.Get("ProjectTitle",ProjectName))
if(tbl.Get("ProjectName",ProjectName))
MessageBox(NULL,"Inside","",0);
fprintf(file,"ProjectTitle: %s\n",ProjectName);
//catName=CategoryName;
ProjectInfo[ProjectArrCnt].ProjectName=ProjectName;
//sprintf(buf,"%s",ProjectName);
MessageBox(NULL,(LPCSTR)ProjectName,"",0);
else
tbl.GetErrorErrStr(ErrStr);
fprintf(file,"Error: %s\n",ErrStr);
break;
ProjectArrCnt++;
//MessageBox(NULL, "While", "WIN API Test",0);
tbl.MoveNext();
//MessageBox(NULL, ProjectInfo[i].ProjectName.c_str(),"f Name", 0);
::CoUninitialize();
//sprintf(buf,"%s",file);
//MessageBox(NULL,buf,"File",0);
fprintf(file, "Connection closed\n");
fclose(file);
for(i=0;i<ProjectArrCnt;i++)
sprintf(buf,"%i",ProjectInfo[i].ProjectID);
//MessageBox(NULL,buf,"Proj ID",0);
//MessageBox(NULL,ProjectInfo[i].ProjectName.c_str(),"Project Name",0);
return 0;
In the above code im geeting project D which is an integer value. But not able to get the project name.
Please some one guide me.As I said in the other thread, this really isn't the place to ask questions about a database API unrelated to the Illustrator SDK. You're far more like to find people familliar with your problem on a forum that is dedicated to answering those kinds of questions instead.
-
How to get values from a table(in jsp) for validation using javascript.
hi,
this is praveen,pls tell me the procedure to get values from a table(in jsp) for validation using javascript.
thank you in advance.Yes i did try the same ..
BEGIN
select PROD_tYPE into :P185_OFF_CITY from
magcrm_setup where atype = 'CITY' ;
:p185_OFF_CITY := 'XXX';
insert into mtest values ('inside foolter');
END;
When i checked the mtest table it shos me the row inserted...
inside foolter .. Now this means everything did get execute properly
But still the vallue of off_city is null or emtpy...
i check the filed and still its empty..
while mtest had those records..seems like some process is cleaining the values...but cant see such process...
a bit confused..here..I tried on Load after footer...
tried chaning the squence number of process ..but still it doesnt help
some how the session variables gets changed...and it is changed to empty
Edited by: pauljohny on Jan 3, 2012 2:01 AM
Edited by: pauljohny on Jan 3, 2012 2:03 AM -
Syndicating Key mapping value from lookup table
Hi Experts,
I want to Syndicating Remote Key value from lookup table as per the remote system.
In syndicator, if I map destination field to the remote key of the lookup table, I am getting blank value.Hi Mrinmoy,
kindly check in the Data Manger whether have you maintained Remote keys for the lookup table. If yes then choose the specified remote system from Remote key override fields under Map properties in the syndicator.
Incase you cant find the remote system in the "remote key override" field for which remote key is assigned in Data manager, then you need to check the Type (outbound) of the remote system in Console admin node. Because only those Remote systems type set as Outbound can been found in Remote key Override in the syndicator.
After choosing the remote key you need to map the destination field with Remote key value as shown in the below image.
Regards
Rahul -
Loading Data from multiple tables into essbase using ODI
Hi,
We have a scenario where data comes from multiple tables. I would like to know how will ODI load this data for the right combination of the membersHi,
I take it each data table has a field which maps to the other table. You can just drag the datastores on to the source interface and create a join between the tables.
Cheers
John
http://john-goodwin.blogspot.com/ -
Create XML (using DTD) from multiple relation tables
Hello and thank you in advanced.
I'm trying to create an XML document, based on a specific DTD, by selecting information from multiple tables in the database.
Is there a tool (in XDK maybe?) that will allow me to map my relational tables to a specific DTD?
I could build the XML manually, but I was hoping that Oracle has already solved this problem with an automated tool.
Thanks again,
Sean CloutierIs that the same thing as me writing an XSQL document which contains all of my queries (or views).
In other words, do I have to map everything by hand or is there a tool to do that for me?
thanks again,
Sean
null -
POWL accessing data from multiple tables/objects
Hello,
I have a query on the POWL applications.
If the powl application has to access data from multiple tables/objects, then the solution would be creating a data structure of those tables/objects and referring to that structure in GET_OBJECT_DEF methods.
Is there any other soln? or I am right here?
The queries which are saved for a particular user are transportable? if not, how can they be made transportable?
Thanks & regards,
Ravishyou are right, you can do in get_objects method.
POWL_QUERIES are transportab;e, you can save them in POWL_QUERY transaction.
Best regards,
Rohit
http://wiki.sdn.sap.com/wiki/display/WDABAP/POWL -
Values from CRCO Table.
Hi all ,
I need to retreive some values from CRCO table based on the balues fetched from AFRU table. I am writing a select like this
select single KOKRS KOSTL into table itab from CRCO
where OBJTY = 'A'
and OBJID = AFRU-ARBID
and ENDDA >= AFRU-BUDAT
and BEGDA <= AFRU-BUDAT.
As I need to retreive a single record from above select, but as a result i am getting multiple records.
Can anybody tell me what other keys from AFRU I can specify in the select in order to fetch only a single record.
Thanks,
Mungala.Object ID you can get from ARBID from AFRU Table. Put value of ARBID in OBJID in table CRCO & get values of KOKRS & KOSTL. That value will be unique for an work center But if ARBID values are many for an AUFNR(order no.) that mean you are using different work center where in may be you are using different cost center(i think controlling area will remain same). & hence SAP creates different records.
Regards
Prashant Jaiswal -
How to get input text values from adf table - Urgent
Hi Friends,
This is my requirement. I designed customized master - detail - detail page. I customized the page in below format.
1. Master Data Field (Input text,etc) .
2. Detail in table format ( Rows are mapped to child table) and i given two buttons for to create row and delete row. I designed the table based on the example provided in forum for to create customized table. The input text component is mapped to the rows.
Now i want to retrieve all the data's entered in the rows. The table is mapped to child table. When i read the values from the table its showing null.
If any one faced this problem and fixed it, please send me the solution.
Thanks & Regards
VBDid you look into the valueChangeEvent?
It has oldValue and newValue attributes.
public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
Object oldVal = valueChangeEvent.getOldValue();
Object newVal = valueChangeEvent.getNewValue();
// check if you see what you are looking for.....
getSelectedRow();
SaveMaterial(material);
}Timo -
How to get edited row values from ADF table?
JDev 11.
I have a table which is populated with data from Bean.
I need to save changes after user make changes in any table cell. InputText is defined for table column component.
I have defined ValueChangeListener for inputText field and AutoSubmit=true. So when user change value in inputText field, method is called:
public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
getSelectedRow();
SaveMaterial(material);
This method should call getSelectedRow which take values from selected table row and save them into object:
private Row getSelectedRow(){
RichTable table = this.getMaterialTable();
Iterator selection = table.getSelectedRowKeys().iterator();
while (selection.hasNext())
Object key = selection.next();
table.setRowKey(key);
Object o = table.getRowData();
material = (MATERIAL) o;
System.out.println("Selected Material Desc = "+material.getEnumb());
return null;
Problem is that getSelectedRow method doesnt get new (edited) values, old values are still used.
I have tried to use ActiveButton with same method and it works fine in that case. New values are selected from active row and inserted into object.
JSF:
<af:table var="row" rowSelection="single" columnSelection="single"
value="#{ManageWO.material}" binding="#{ManageWO.materialTable}">
<af:column sortable="false" headerText="E-number">
<af:inputText value="#{row.enumb}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
</af:column>
<af:column sortable="false" headerText="Description">
<af:inputText value="#{row.desc}" valueChangeListener="#{ManageWO.SaveMaterial}" autoSubmit="true"/>
</af:column>
</af:table>
<af:activeCommandToolbarButton text="Save" action="#{ManageWO.EditData}"/>
What is a correct place from where save method should be called to get new (edited) values from ADF table?
Thanks.Did you look into the valueChangeEvent?
It has oldValue and newValue attributes.
public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
Object oldVal = valueChangeEvent.getOldValue();
Object newVal = valueChangeEvent.getNewValue();
// check if you see what you are looking for.....
getSelectedRow();
SaveMaterial(material);
}Timo -
How to extract data from multiple tables (always got errors)
Dear Experts,
I have a simple mapping to extract data from multiple tables as a source (A, B, C) to a target table (X). Below is the picture:
(Sources)....(Target)
A----------------***
B----------------X
C----------------***
Sample Source Data:
Table A:
ColA1
100
200
etc
Table B:
ColB1 ColB2 ColB3
10 Y Ten
20 Y Twenty
30 Y Thirty
etc
Table C:
ColC1 ColC2
11
12
13
etc
Target table (X) should be (just has 1 group INGRP1):
ColA1 ColB1 ColB3 ColC1
100 10 Ten 11
100 10 Ten 12
100 20 Twenty 21
etc
Scenarios:
1. Directly map from A, B, C to X. Unable to map with error message: "API8003: Connection target attribute group is already connected to an incompatible data source. Use a Joiner or Set operator to join the upstream data first before connecting it into this operator."
2. Map each source to Expression Operator and then map from each Expression to target table. I am able to map all attributes successfully but got error when validating it with message: "VLD-1104: Attributes flowing into TEST.EXPR_SRC.INGRP1 have different data sources."
How can I achieve the correct mapping for this purpose?
Use Joiner? I have no key to join the sources
Use Set? The sources have different number of columns
Thanks in advance
PratThanks Nico,
I think it will results data like this:
100 10 Ten 11
200 20 Twenty 12
300 30 Thirty 13
etc
and not the expected:
100 10 Ten 11
100 10 Ten 12
100 20 Twenty 21
etc
But it inspired me to solve this by adding key expression in each source table (B & C) to be joined to table A with this formula:
100+TRUNC(INGRP1.COLB1,-2)
Regards
Prat -
How to select distinct values from a table when it has composite primary ke
Hi
I have the requirement like , I need to select distinct one column values from the table which has composite primary key. How to acheive this functioinality using view object.
Eg : Table 1 has col1 and col2, col3
col1 col2 col3
1 A NA
1 B NA
2 A NA
3 C NA
2 D NA
primary key (col1,col2)
I have to select distinct col1.
ThanksHi
I got the solution for above. By Creating the read only view object we can acheive this.
thanks
Maybe you are looking for
-
Displaying selection screen details in Alv Report output display as Header
Hi all, May be somebody knows how I can show selected values with select-options in top_of_page using REUSE_ALV_GRID_DISPLAY. This shoud work for all the reports and diff selection screens . I need one dynamic process which will for display any repor
-
I´ve got an iTunes 10.4 for PC and i want to update it to iTunes 10.5 in order to get the iOS5 update. I have successfully downloaded the Setup package, But when it comes to the "updating" comes the trouble. When the update progress is almost finishe
-
Can you do that with the SDK?
I have a question concerning the SDK. In a project, we want to automate some Editing-Functions and the "Premiere_SDK_Guide.pdf" leaves some questions: 1) Is it possible to write a plugin, that read pathes from ressources (for example Images and Audio
-
Problem/Error with 'Document' demo!
the "document" demo does not seem to work correct (in my case: Oracle 8.1.6, xsql servlet version 1.0.0.0 (Production) and MSIE 5.5). The demo lets you insert a XML-document in a table and retrieve it afterwards. The retreiving part does not work. Th
-
ICloud Keychain showing too many devices?
I have a strange problem that's currently frustrating me. I have 4 devices, an iPhone 5, iPad 2, MacBook Air and iMac. It all started when I began to have trouble with my MacBook Air (another story). I've since setup Mavericks a couple of times on th