ONE-to-MANY relationship between tables and forms in APEX
I recently started using APEX and I have run into an issue.
I have a ONE-TO-MANY relationship between two tables, A1 and A2, respectively.
A1:
A1_ID
Item
A2:
A2_ID
SubItem
A1_ID
I have 2 forms (lets call it F1 and F2) that I use to capture data for A1 and A2.
On F2, I have the following fields that are setup to capture data:
A2.A1_ID
**A1.Item (this is a drop down that is populated using a SELECT statement where the select uses A1.Item field)
A2.SubItem (user would enter SubItem)
Note: A2.A2_ID is populated using a SEQ
Everytime I pick **A1.Item on F2, is there a way to link to A1 table and display A1.A1_ID for every **A1.Item selected on F2?
If so, I want to store the value captured in F2 for the A1_ID field into A2 table to maintain my 1-to-MANY relationship.
If this will work, how do I go about implementing this solution?
Can someone help me?
I think it sounds like you are asking for a Master-Detail form. Try that and see what you get.
chris.
Similar Messages
-
i have three tables A,B,C. there is one to many relation between A and B. and one to many relation existed between table b and c . how will get data from these three tables
check if this helps:
select * --you can always frame your column set
from tableA a
left join tableB b on a.aid=b.aid
left join tableC c on c.bid=b.bid
This is just a general query. However, we can help you a lot more, if you can post the DDL + sample data and required output.
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
Many to many relationships between Fact and Dimension
Hi All,
I have to solve two kind of many to many relationships between Fact and Dimension.
1. Many to Many relationship between Fact and Dimension, using a bridge table, with FKs in fact and dimension to bridge tables PK.
2. Many to Many relationship between Fact and Dimension, using a bridge table, and an intersection table, with FK in fact to bridge table, and 2 FKs in intersection table to Dimension and to bridge table.
I need help on implementing (how the mapping has to look like) them in OWB 9.2.0.2.8.
Thanks,
Aurelian CojocaruAurelian,
Unfortunately, you cannot implement this in the dimensional model. You would have to use relational tables and relationships between those in order to implement your scenario.
Thanks,
Mark. -
Many to many relationship between category and category set?
Is there a many to many relationship between category
and category sets in Inventory mgmt?
I mean, one category can exist in many category sets
and one category set can have many categories, is that true?Is there a many to many relationship between category
and category sets in Inventory mgmt?
I mean, one category can exist in many category sets
and one category set can have many categories, is that true? -
How to implement one to many relationship between two Document Line Table
Hi,
I want to implement the following relationship into user defined tables:
Example Situation:
There are tables A, B and C.
For one record of Table A, there could be multiple records in table B.
For one record of Table B, there could be multiple records in table C.
i.e. A(1) -> B(n) [One to many relationship]
B(1) -> C(n) [One to many relationship]
finally: A(1) -> B(n) -> C(n)
How can I achieve this? If I make Table A as Document and table B & C as Document Line and then make them UDO, will it work? Kindly suggest me a solution.
Regards,
Sudeshna.Hi,
I think that the database representation is exactly what you ask for. 3 tables, A, B, C. A should have a UDF that is linked to B table, and B should have a UDF that is linked to C table.
You should manage the database transactions, and the UI to support all this stuff.
Regards,
IBai Peñ -
Unidirectional one-to-many with join table
According to http://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/associations.html#assoc-unidirectional-12m "A unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended", instead they recommend using a join table, e.g.
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId not null, addressId bigint not null primary key )
create table Address ( addressId bigint not null primary key )
However if doing this, when using SQLDeveloper the Address table does not appear as a child table of Person, which it should be as a unidirectional one-to-many meaning that I can't create a cache group for Person and subsequently Person.
Is this something that can be worked around as I'm using a legacy schema created from Hibernate/JPA and the implications of changing are quite substantial?
ThanksHi Gennady,
Apologies but my question was not clear enough. The schema structure that I have inherited is as follows:
CREATE TABLE T_PERSON ( PERSONID NUMBER PRIMARY KEY, PERSONFIRSTNAME VARCHAR2(20), PERSONLASTNAME VARCHAR2(20) );
CREATE TABLE T_PERSONADDRESS (PERSONID NUMBER NOT NULL, ADDRESSID NUMBER NOT NULL PRIMARY KEY );
CREATE TABLE T_ADDRESS ( ADDRESSID NUMBER PRIMARY KEY, ADDRESSTEXT VARCHAR2(200) );
ALTER TABLE T_PERSONADDRESS ADD CONSTRAINT FK_PERSON_ADDR_PERSON_ID FOREIGN KEY (PERSONID) REFERENCES T_PERSON(PERSONID);
ALTER TABLE T_PERSONADDRESS ADD CONSTRAINT FK_PERSON_ADDR_ADDR_ID FOREIGN KEY (ADDRESSID) REFERENCES T_ADDRESS(ADDRESSID);This is implementing a unidirectional one-to-many relationship between T_PERSON and T_ADDRESS according to the Hibernate and JPA recommendation. As far as I can see most schema designers would do this using by adding a column "PERSON_ID" (and associated FK) on the T_ADDRESS table and therefore not needing the T_PERSONADDRESS table.
This being what it is, I would then like to create a cache-group as follows:
CREATE READONLY CACHE GROUP "CACHEGROUPADDRESSES"
AUTOREFRESH MODE INCREMENTAL INTERVAL 5 MINUTES
STATE PAUSED
FROM
"SCHEMA1"."T_PERSON" (
"PERSONID" NUMBER NOT NULL,
"PERSONFIRSTNAME" VARCHAR2(20 BYTE),
"PERSONLASTNAME" VARCHAR2(20 BYTE),
PRIMARY KEY("PERSONID")
"SCHEMA1"."T_ADDRESS" (
"ADDRESSID" NUMBER NOT NULL,
"ADDRESSTEXT" VARCHAR2(20 BYTE),
PRIMARY KEY("ADDRESSID")
"SCHEMA1"."T_PERSONADDRESS" (
"PERSONID" NUMBER NOT NULL,
"ADDRESSID" NUMBER NOT NULL,
PRIMARY KEY("ADDRESSID"),
FOREIGN KEY("PERSONID")
REFERENCES "SCHEMA1"."T_PERSON"("PERSONID"),
FOREIGN KEY("ADDRESSID")
REFERENCES "SCHEMA1"."T_ADDRESS"("ADDRESSID")
)This however gives me the error "TT8222: Multiple parent tables found" because TimesTen has failed to identify the one-to-many-using-link-table pattern.
Without a schema re-write is there anything that I can do, alternatively will this be looked at for a future release of TimesTen?
Edited by: TrisStev on Apr 16, 2012 10:37 AM -
One-to-many relationship: problem with several tables on the one side...
Hello
I'm having problems developing a database for a content management system. Apart from details, I've got one main table, that holds the tree structure of the content ("resources") and several other tables that contain data of a particular datatype ("documents", "images", etc.). Now, there's one-to-many relationship between "resources" table and all the datatype tables - that is, in the "resources" table there's "resource_id" column, being a foreign key referenced to the "id" columns in the datatype tables.
The problem is that this design is deficient. I can't tell form the "resource_id" column from which datatype table to get the data. It seems to me that one-to-many relationship only works with two tables. If the data on the one side of the relationship is contained in several tables, problems arise.
Anybody knows a solution? I would be obliged.
Regards
HavocadoHi;
A simple way may be create a view on referenced tables:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL>
SQL> drop table resources;
Table dropped
SQL> create table resources(id number, name varchar2(12));
Table created
SQL> insert into resources values(1,'Doc....');
1 row inserted
SQL> insert into resources values(2,'Img....');
1 row inserted
SQL> drop table documents;
Table dropped
SQL> create table documents(id number, resource_id number,type varchar2(12));
Table created
SQL> insert into documents values(1,1,'txt');
1 row inserted
SQL> drop table images;
Table dropped
SQL> create table images(id number, resource_id number,path varchar2(24));
Table created
SQL> insert into images values(1,2,'/data01/images/img01.jpg');
1 row inserted
SQL> create or replace view vw_resource_ref as
2 select id, resource_id, type, null as path from documents
3 union
4 select id, resource_id, null as type, path from images;
View created
SQL> select * from resources r inner join vw_resource_ref rv on r.id = rv.resource_id;
ID NAME ID RESOURCE_ID TYPE PATH
1 Doc.... 1 1 txt
2 Img.... 1 2 /data01/images/img01.jpg
SQL> Regards.... -
One to Many with multiple tables on One side and one table on Many side
Sorry for the confusion in the title. Here is my question. In my program, I have 2 different tables which store 2 different type of entities. Each one of entities has a list of attachments which I stored in a common attachment table. There is a one-to-many relationship between entity tables and attachment table.
ENTITY_ONE (
ID
NAME
ENTITY_TWO (
ID
NAME
ATTACHMENTS (
ID
ENTITY_ID
ATTACHMENT_NAME
ENTITY_ID in ATTACHMENTS table is used to link attachments to either entity one or entity two. All IDs are generated by one sequence. So they are always unique. My question is how I could map this relationship into EntityOne, EntityTwo and Attachment JAVA class?For EntityOne and EntityTwo you can just define a normal OneToMany mapping using the foreign key.
Are you using JPA, or the TopLink API? JPA requires a mappedBy for the OneToMany, so this may be more difficult. You should be able to just add a JoinColumn on the OneToMany and make the column insertable/updateable=false.
For the attachment, you could either map the foreign key as a Basic (DirectToFieldMapping) and maintain it in your model, or use a VariableOneToOne mapping in TopLink (this will require the entities share a common interface).
James : http://www.eclipselink.org : http://en.wikibooks.org/wiki/Java_Persistence -
Newbie: one to many relationship SQL error
Greetings all-
This is probably a slam dunk for you JDO experts. I'm a JDO newbie, working
with an existing schema in MySQL. I have a one to many relationship between
two tables:
Table "company":
Fields:
company_id: int(11) -- primary key
name : varchar(64)
division : varchar(64)
Table "company_products"
Fields:
company_id: int(11) -- foreign key to table company
product_name: varchar(64)
product_description: varchar(64)
So, I created the corresponding classes:
public class Company {
private int companyID;
private String company_name;
private String division;
// Array of CompanyProduct
private ArrayList companyProducts;
// .. methods omitted
public class CompanyProduct {
private int companyID;
private String productName;
private String productDesc;
// Methods omitted
Then I created the "package.jdo" file:
<?xml version="1.0"?>
<jdo>
<package name="com.packexpo.db">
<class name="Company">
<extension vendor-name="tt" key="table" value="company"/>
<extension vendor-name="tt" key="pk-column" value="company_id"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="companyID">
<extension vendor-name="tt" key="data-column" value="company_id"/>
</field>
<field name="name">
<extension vendor-name="tt" key="data-column" value="name"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
<field name="division">
<extension vendor-name="tt" key="data-column" value="division"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
<field name="companyProducts">
<collection element-type="com.packexpo.db.CompanyProduct"/>
<extension vendor-name="tt" key="inverse" value="companyID"/>
</field>
</class>
<class name="CompanyProduct">
<extension vendor-name="tt" key="table" value="company_product"/>
<extension vendor-name="tt" key="pk-column" value="company_id"/>
<extension vendor-name="tt" key="lock-column" value="none"/>
<extension vendor-name="tt" key="class-column" value="none"/>
<field name="companyID">
<extension vendor-name="tt" key="data-column" value="company_id"/>
</field>
<field name="productName">
<extension vendor-name="tt" key="data-column" value="product_name"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
<field name="productDesc">
<extension vendor-name="tt" key="data-column"
value="product_description"/>
<extension vendor-name="tt" key="column-length" value="64"/>
</field>
</class>
</package>
</jdo>
Enhancement works fine. I successfully query and retrive Company objects
from the database, but as soon as I try to get the list of CompanyProducts,
I get an SQL Error:
javax.jdo.JDODataStoreException: [SQL=SELECT company.COMPANYPRODUCTSX FROM
company WHERE company.company_id = 82061]
E0610 Error in executeQuery()
E0606 executeQuery() error --
E0701 Error in getResult().
E0708 Command results in error - 1054 Unknown column
'company.COMPANYPRODUCTSX' in 'field list'
NestedThrowables:
com.solarmetric.kodo.impl.jdbc.sql.SQLExceptionWrapper: [SQL=SELECT
company.COMPANYPRODUCTSX FROM company WHERE company.company_id = 82061]
E0610 Error in executeQuery()
E0606 executeQuery() error --
E0701 Error in getResult().
E0708 Command results in error - 1054 Unknown column
'company.COMPANYPRODUCTSX' in 'field list'
I know i have probably set up the package.jdo file incorrectly, but I'm at a
loss for what I did wrong.
Any suggestions?
Thanks!
-MikeHi,
915766 wrote:
I need to write sql for below requirement:
table structure is
serial no LPN
1 4
2 4
3 6
4 6
5 6
6 3
7 3
8 3
9 1
I have to pick distinct 'LPN' like below:That sounds like a job for "GROUP BY lpn".
(any serial no can be picked for the distinct LPN)It looks like you're displaying the lowest serial_no for each lpn. That's easy to do, using the aggregate MIN function.
results needs to be as below:
serial no LPN
1 4
3 6
6 3
9 1
Please suggest with sql.Here's one way:
SELECT MIN (serial_no) AS serial_no
, lpn
FROM table_x
GROUP BY lpn
ORDER BY lpn -- if wanted
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), 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 {message:id=9360002} -
One to many relationship leads to recursion?
Hi,
I've created a web services function which returns an object retrieved from a database using the persistence api (the class was generated by the Netbeans 5.5 "Entity Class from Database" feature.
I can successfully return an object which has no foreign keys. However, when I try to retrieve an entity which is on either side of a 1:N relationship, I receive a stackOverflowError.
Here's my sample schema (I'm using Derby bundled with SJAS 9 for testing)
create table Address (
Id int not null,
StreetName varchar(255),
City varchar(255),
PostalCode varchar(255),
Party int,
primary key (Id)
create table Party (
Id int,
Name varchar(255),
primary key(Id)
alter table Address add constraint foreign key (Party) references Party;So as you can see, one Party might have many addresses.
I can retrieve either an Address or Party from the database using something like:
em.createNamedQuery("Party.findById")
.setParameter("id", 1)
.getSingleResult();When I try to return it, I get a stackOverflowError in the server log. I'm using the default Toplink provider so enabling full logging on this, I can see the SQL.
When retrieving an address, it selects all of the address fields and correctly binds the supplied Id value. It then performs a select on the Party table using the Address.Party value. This in turn causes it to attempt to retrieve an Address. After three queries, the error is thrown.
I can't see why the above schema should cause this problem. Where an Address is requested, I would expect it to retrieve the address fields, including the value of the Party field but not the Party object itself. On the other hand. when a Party is retrieved, I would expect it to recurse through and return a collection of Address objects.
Have I misunderstood this or am I missing some fundamental point about JAX-WS?
Thanks for your help,
-PhilYou have to set both sides of the relations...
for example to do this in a more seamless manner:
public UserProfile
public void addLog (UserActivityLog activity)
logs.add (activity);
if (!equals (activity.getUserProfile ()))
activity.setUserProfile (this);
Now this is the most primitive of ways to maintain two sided relations.
There are a lot of other patterns to get around this.
If you want to set the UserActivityLog to a specific UserProfile without
having a firm reference to ther UserProfile, you should get the object
from the database/persistenceManager... as you are using application
identity, you can do something like pm.getObjectById.
JDO does not do magic references. If you set something to null, it will
remain null until you set it.
Srini wrote:
Hi Guys
I am trying to create a one to many relationship between 2 JDOs.
UserProfile - User JDO having user info
UserActivityLog - JDO having user log info
UserProfile -- UserActivityLog
1 many
UserProfile - has a collection of UserActivityLog objects
UserActivityLog - has a reference to UserProfile
Qn 1:
I created a UserProfile along with a collection of 2 UserActivityLog
objects.
Navigation:
Now given a UserProfile object,i am able to get the UserActivityLog objects.
But given a UserActivityLog object ,i get a NULL UserProfile object.
Issues:
Why this is happening???Do i need to set the reference for "UserProfile" in
UserActivityLog before inserting???
If so,then how do i add a UserActivityLog to an existing
UserProfile???cos,if i create a UserActivityLog with reference to
UserProfile ,then it will throw a Duplicate Key violation for UserProfile as
it is already persisted in DB.
It will be great if you can direct me to some one to many relationship
examples already implemented.
Thanks
Srini
Stephen Kim
[email protected]
SolarMetric, Inc.
http://www.solarmetric.com -
Summarizing data in a one-to-many relationship
Post Author: Bob Amiral
CA Forum: General
I use an order tracking system that has a one to many relationship between the main order information file and the line items file. For each order, there can be one or more items in the items file. I am having no luck trying to summarize data in such a way that shows selected information from the order file with only a summary from the item file on one line. Instead, the reports expands by adding a line for each and every entry from the item file that relates to the order.
How can I summarize data from the item file to show only one line of item data in the same line as the order data?Post Author: Charliy
CA Forum: General
Group by Order #
Suppress the Detail (and possibly the Group Header, depending on how you want it to look)
Put Running Totals in the Group Footer that reset on change of group. -
One-to many relationship in EJB
hi forum
wish you a very happy and prosperous new year
i want to implement CMR in my project but to start with i tried sample application setting one-to many CMR between EMP and DEPT table of scott/tiger .the problem is i have to modify my orion-ejb-jar.xml how can we do it?Are you using JDeveloper? JDeveloper automatically creates the orion-ejb-jar.xml file when you use the EJB wizard.
-
SELECT on One to many Relationship
Hi am trying to run a select statement on one to many relationship.
TableA is the main table with acount number and Total_Payments
TableB,TableC and TableD have a lot of account number and payments
per day
Note an account might on TableA might not be on TableB or TableC since it was not paid for that day hence 'if it is Null i'll like to populate a zero.
OUTPUT should be :
TableA.Account_No | Total_Amount(amounts from TableB/C/D)
Regards.Hello,
Please refer to the following statements. If I have any misunderstand, please post the DDL of the tables and sample data for further analysis:
SELECT A.account, SUM(ISNULL(B.payment,0)+ISNULL(C.payment,0)+ISNULL(D.payment,0)) As Total_Amounts
FROM TableA A LEFT JOIN TableB B ON A.account=B.account
LEFT JOIN TableC C ON A.account=C.account
LEFT JOIN TableD D ON A.account=D.account
GROUP BY A.Account
Regards,
Fanny Liu
If you have any feedback on our support, please click here.
Fanny Liu
TechNet Community Support -
The Relation between tables and views in oracle financial
Dears
I am work in oracle e business r12
and i need to build report as xml
when run my select its need big time to view data i have a huge of data so i need to clear the relation of this tables if there is miss and if there another technique in select statement
this is my select statement
select
j_hdr.je_header_id je_header_id,
hdr.VENDOR_NAME supplier,
SEGMENT1||'-'||SEGMENT2||'-'||SEGMENT3||'-'||SEGMENT4||'-'||SEGMENT5||'-'||SEGMENT6||'-'||SEGMENT7||'-'||SEGMENT8||'-'||SEGMENT9 Account_number,
hdr.gl_date gl_date,
j_hdr.CURRENCY_CODE CURRENCY_CODE,
inv_lin.DESCRIPTION DESCRIPTION,
j_lin.ENTERED_DR ENTERED_DR,
j_lin.ENTERED_CR ENTERED_CR,
j_lin.ACCOUNTED_DR ACCOUNTED_DR,
j_lin.ACCOUNTED_CR ACCOUNTED_CR,
j_hdr.JE_SOURCE JE_SOURCE,
j_hdr.DEFAULT_EFFECTIVE_DATE Transaction_DATE,
hdr.INVOICE_NUM INVOICE_NUM,
QUICK_PO_NUMBER PO_NUMBER,
null ASSET_CATEGORY_ID,
hdr.VENDOR_ID VENDOR_ID
from gl_je_headers j_hdr,gl_je_lines_v j_lin,ap_invoice_distributions dist,ap_invoices_v hdr,ap_invoice_lines_v inv_lin
where code_combination_id = DIST_CODE_COMBINATION_ID
and hdr.invoice_id = inv_lin.INVOICE_ID
and dist.invoice_id = inv_lin.INVOICE_ID
and j_hdr.JE_HEADER_ID = j_lin.JE_HEADER_ID
and j_hdr.status = 'P'
and nvl(:P_SOURCE,'Payables') = 'Payables'
and je_source = 'Payables'
and j_lin.CODE_COMBINATION_ID between ( select CODE_COMBINATION_ID
from gl_code_combinations_kfv
where CONCATENATED_SEGMENTS = :P_FROM_COMBINATION_CODE)
and ( select CODE_COMBINATION_ID
from gl_code_combinations_kfv
where CONCATENATED_SEGMENTS = :P_TO_COMBINATION_CODE)
AND TRUNC(dEFAULT_EFFECTIVE_DATE) BETWEEN NVL(:P_FROM_DATE, DEFAULT_EFFECTIVE_DATE) AND NVL(:P_to_DATE, DEFAULT_EFFECTIVE_DATE)
Thanks in advanceWelcome to the world of complicated Oracle Application queries. Didn't fully understand your question, so a few guesses -
I think that you are asking how to make your query faster? I would reference the FAQ section on how to post a question regarding performance.
Your title indicates you want to understand the relationship between tables and views. In general, Oracle Applications uses views for 2 reasons - to join data from multiple tables for display, and to differentiate data from different organizations. (I am still on 11i and have heard organizations are handled differently in 12 so I can't speak to that for sure).
To understand the relationship between tables in a view, you can access the view's source code, either through a development tool such as PL/SQL Developer or TOAD (I'm guessing Oracle's tool does this also, but have never used it), or by querying the source from the dba_source table.
select * from dba_source where name = (name of view) and type = 'VIEW' order by line;without the ( ) just the view name, in all capital letters i.e. , 'GL_JE_LINES_V'
Good luck! -
SET One to many Relationship in MSSQL
How can i set one to many relationship in TABLE ?
Just curious, Why did you add Name here below?
CONSTRAINT PK_Student PRIMARY KEY CLUSTERED
EnrolNo, Name
Try the below:
INSERT INTO Student (EnrolNo, Name, ClassID) VALUES
(3256, 'Sara1', 1)
Maybe you are looking for
-
How much ram can my device take MacBook 6'1
I have a MacBook 6'1 Late 2009 model. How much DDR3 RAM can it take
-
Error 4000 burning CDs with iTunes 7.1
iTunes checks the disc, then burns 3-4 songs, then cancels the CD burn wasting yet another disc. Also, I cannot backup my purchased songs with the backup feature. I get the same error 4000 when attempting to make a backup disc. These problems only be
-
Sorry to repost but has anybody used a TV Mini with their MBP - some people are saying it dosent work with the MBP. If anyone has used a TV Mini could you tell me: Does it have good picture and sound quality? Is it hard to get a signal? Do you have t
-
Dear Experts, I am sure SAP follows the same concepts in BI as just recently i have worked in JasperSoft Talend Open studio. But i have some doubts with BI. I created a RFC in ABAP. Used that RFC to bring data for a single day as parameter on to ing
-
2 node cluster windows 2008 R2 cluster won't form
Hi, I'm trying to build a 2 node cluster and having no luck at all. My validation works great but when I go to create the cluster it fails on the forming cluster section after about 2 minutes. I seem to have everything in order and can't figure o