Workbench-Cannot Give Joining to One-To-Many
Hi there,
i am using toplink workbech 10g release 2(10.1.3.0DP4) build 050715. In workbench, i want to put "use joining" to a one-to-many relationship. Joining can be applied to one-to-many relationships from the java code but in workbench i cannot give joining to the one-to-many relationships. There is no checkbox for that property. I can only check batch reading. Is it true, or is there a problem with my mapping workbench?
This is true, there is currently no 1-m joining support in the Mapping Workbench, nor can you set this at the mapping level in the code API. 1-m joining can only currently be set at the query level in the code API. Note that in general batch reading for 1-m is more performant than joining, so you may want to consider using it instead.
Similar Messages
-
Aggregate one-to-many relationship problem
Hello,
After migrating from Toplink 9i I've stumbled across a problem with our aggregate objects.
Toplink Workbench reports no errors and generates a nice XML but in runtime I get this error whenever a aggregate function is used.
[TopLink fin]: 2008.02.13 03:18:11.552--ServerSession(12626425)--Connection(29948747)--Thread(Thread[main,5,main])--SELECT DISTINCT t0.NPL_PACK_ID, t0.NPL_ID FROM NPL_MEDPROD t3, FASS_MEDPROD t2, NPL_MEDPROD t1, NPL_PACKAGE t0 WHERE (((t0.NPL_ID = t1._Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test) AND ((t1.NPL_ID = t2.NPL_ID) AND (t3.NPL_ID LIKE '19750613000031%'))) AND (t3.NPL_ID = t2.NPL_ID))
Caused by: Undantag [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.DatabaseException
Internt undantag: java.sql.SQLException: ORA-00911: invalid character
Felkod: 911
I belive that problem resides in this clause :
t1._Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test
I've created a small test project with just a couple of classes but the same aggregate problem occurs which has let me to believe the problem does not come from the migrating process which was my first guess. If anyone could help me discover what I am doing wrong it would be very appreciated. Below is my test project output.
<?xml version="1.0" encoding="UTF-8"?>
<toplink:object-persistence version="Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)" xmlns:opm="http://xmlns.oracle.com/ias/xsds/opm" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:toplink="http://xmlns.oracle.com/ias/xsds/toplink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<opm:name>test</opm:name>
<opm:class-mapping-descriptors>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>se.lif.fass.fassdata.impl.FASSMedProdImpl</opm:class>
<opm:alias>FASSMedProdImpl</opm:alias>
<opm:primary-key>
<opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:primary-key>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:one-to-one-mapping">
<opm:attribute-name>_Medprod</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl</opm:reference-class>
<opm:private-owned>true</opm:private-owned>
<opm:foreign-key>
<opm:field-reference>
<opm:source-field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:field-reference>
</opm:foreign-key>
<opm:foreign-key-fields>
<opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:foreign-key-fields>
<toplink:batch-reading>true</toplink:batch-reading>
<toplink:selection-query xsi:type="toplink:read-object-query"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>id</opm:attribute-name>
<opm:read-only>true</opm:read-only>
<opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>independent</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
<toplink:tables>
<toplink:table name="FASS_MEDPROD"/>
</toplink:tables>
</opm:class-mapping-descriptor>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>schemas_npl.instance.impl.MedprodTypeImpl</opm:class>
<opm:alias>MedprodTypeImpl</opm:alias>
<opm:primary-key>
<opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:primary-key>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:aggregate-object-mapping">
<opm:attribute-name>_Medprodpack</opm:attribute-name>
<toplink:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl</toplink:reference-class>
<toplink:allow-null>false</toplink:allow-null>
<toplink:field-translations>
<toplink:field-translation>
<toplink:source-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
<toplink:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</toplink:field-translation>
</toplink:field-translations>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>_Nplid</opm:attribute-name>
<opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>id</opm:attribute-name>
<opm:read-only>true</opm:read-only>
<opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>independent</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
<toplink:tables>
<toplink:table name="NPL_MEDPROD"/>
</toplink:tables>
</opm:class-mapping-descriptor>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl</opm:class>
<opm:alias>MedprodTypeImpl$MedprodpackTypeImpl</opm:alias>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:one-to-many-mapping">
<opm:attribute-name>_Presentation</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:reference-class>
<opm:private-owned>true</opm:private-owned>
<opm:target-foreign-key>
<opm:field-reference>
<opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
</opm:field-reference>
</opm:target-foreign-key>
<toplink:batch-reading>true</toplink:batch-reading>
<toplink:container xsi:type="toplink:list-container-policy">
<toplink:collection-type>com.sun.xml.bind.util.ListImpl</toplink:collection-type>
</toplink:container>
<toplink:selection-query xsi:type="toplink:read-all-query">
<toplink:container xsi:type="toplink:list-container-policy">
<toplink:collection-type>com.sun.xml.bind.util.ListImpl</toplink:collection-type>
</toplink:container>
</toplink:selection-query>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>aggregate</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
</opm:class-mapping-descriptor>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:class>
<opm:alias>MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:alias>
<opm:primary-key>
<opm:field table="NPL_PACKAGE" name="NPL_PACK_ID" xsi:type="opm:column"/>
</opm:primary-key>
<opm:events xsi:type="toplink:event-policy"/>
<opm:querying xsi:type="toplink:query-policy"/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>_Nplpackid</opm:attribute-name>
<opm:field table="NPL_PACKAGE" name="NPL_PACK_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:one-to-one-mapping">
<opm:attribute-name>backref</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl</opm:reference-class>
<opm:foreign-key>
<opm:field-reference>
<opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
</opm:field-reference>
</opm:foreign-key>
<opm:foreign-key-fields>
<opm:field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
</opm:foreign-key-fields>
<toplink:indirection xsi:type="toplink:value-holder-indirection-policy"/>
<toplink:selection-query xsi:type="toplink:read-object-query"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>id</opm:attribute-name>
<opm:read-only>true</opm:read-only>
<opm:field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>independent</toplink:descriptor-type>
<toplink:instantiation/>
<toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
<toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
<toplink:tables>
<toplink:table name="NPL_PACKAGE"/>
</toplink:tables>
</opm:class-mapping-descriptor>
</opm:class-mapping-descriptors>
<toplink:login xsi:type="toplink:database-login">
<toplink:platform-class>oracle.toplink.platform.database.oracle.Oracle8Platform</toplink:platform-class>
<toplink:user-name>fassadmin</toplink:user-name>
<toplink:password>3CC3773C96563CA0C89634305615359CD62D1A19DF561D1E</toplink:password>
<toplink:driver-class>oracle.jdbc.driver.OracleDriver</toplink:driver-class>
<toplink:connection-url>jdbc:oracle:oci8:@DB2</toplink:connection-url>
</toplink:login>
</toplink:object-persistence>
Regards
/JonasThe issue is in the one-to-many mapping in the aggregate,
<br>
<opm:attribute-mapping xsi:type="toplink:one-to-many-mapping">
<opm:attribute-name>_Presentation</opm:attribute-name>
<opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:reference-class>
<opm:private-owned>true</opm:private-owned>
<opm:target-foreign-key>
<opm:field-reference>
<opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
<opm:target-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
</opm:field-reference>
</opm:target-foreign-key>There is an issue with the Mapping Workbench and shared aggregates with one-to-many mappings and translating the foreign key fields. Did this work before, I would be surprized if it did, unless the 2.5 Builder was used?
Anyway the easiest workaround is to either edit the XML and change the NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test column name to what it should be, or define a descriptor amendment method to define the one-to-many mapping with the correct field names.
-- James : EclipseLink -
One to Many table join -- concat field per record grouped by id
Post Author: wm5
CA Forum: Formula
Hello,
I am using Crystal Reports XI and have two tables that have a one to many relationship and are joined by an JobID (number).
Below is a sample with relative fields for each table.
job_table: JobID (number), Manager (text), Status (text)
jobaudit_table : JobAuditID (number), JobID (Number), FormID (Number)
There is a one to many relationship with jobaudit_table having multiple records for each JobID in job_table.
I have created a Group Header using the job_table.JobID and suppressed the detail section.
In the group header for each JobID I display the JobID, Manager, Status. I also use the below formula to determine if any records in the jobaudit_table has a record where FormID = 90. If so, I display "Yes". If not, "No".
So my report currently looks like.
JobID Manager Status Audit Performed
1 Manager 1 Closed N
2 Manager 2 Closed Y
Here are the formula's I use to determine if any records in jobaudit_table contains a record where FormID = 90.
@ja90exists
if {jobaudit_table.FormID} = 90 then 1else 0;
if sum({@ja90exists},{job_table.JobID}) = 0 then "No"else "Yes";
Everything so far works fine. What I would like to do now is add a hyperlink to a script to view the job audit when in the above report the "Audit Performed" column is "Yes"
So Report is now:
JobID Manager Status Audit Performed
1 Manager 1 Closed N
2 Manager 2 Closed Y (hyperlink to view audit)
I cannot figure out how to gather the valid JobAuditIDs where FormID = 90 grouped by JobID to be used in the Group Heading section of the report.
Also, it is unlikely, but possible that more than one job_audit record exists with FormID = 90 per JobID. So, my hyperlink could look like http://mysite.com/viewjobaudit.aspx?jobid=[jobaudit_table.JobAuditID],[jobaudit_table.JobAuditID] .
Thanks for any help. And if this post is not clear let me know and I will clarify.
wm5Post Author: bettername
CA Forum: Formula
Although I can't think of a way to get multiple hyperlinks, this should be a start. It (should) hyperlink to the last job/audit in the group that formID of 90. Oh, I assumed that the hyperlink should have been xxxx...jobID,jobAuditID!
I think there may be a way of getting hyperlinks to every "90" record, but that will involve a subreport, so lets try this first...
1 - everything from your group header to the group footer...
2 - add a formula into the group header that says:
whileprintingrecords;
stringvar jobauditID="";
stringvar jobID:=";
3 - Then add a formula to the details section:
whileprintingrecords;
stringvar jobauditID;
stringvar jobID;
if {jobaudit_table.FormID} = 90
then (jobID:=totext({job_table.job_id},0,""); jobauditID:=totext({jobaudit_table.jobaudit_id},0,"")
4 - Finally, on your "Audit Performed" formula, have a conditional hyperlink that says:
whileprintingrecords;
stringvar jobauditID;
stringvar jobID;
if {@audit performed} = "Y" then http://mysite.com/viewjobaudit.aspx?jobid=jobID","+jobauditID -
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 -
I recently changed my apple id email from an old one to a new one and now I can't sign out of my old one on my iPhone 5 because it says I need a password. I cannot give that password because it is part of the old apple ID. How do I change IDs?
Hi sharonpalencia,
Welcome to the Apple Support Communities!
I understand it can be very frustrating when you cannot sign in, or sign out in this case, to your Apple ID. In this situation you may need to temporarily edit your Apple ID back to the original email address so that you can sign out. Once signed out, edit the Apple ID back to the new email address and sign in. Please use the attached article for further information.
If you're asked for the password to your previous Apple ID when signing out of iCloud
Change your Apple ID temporarily
If signing out and back in to iMessage or FaceTime didn't help, try these steps:
Change your Apple ID to the Apple ID you used previously. You shouldn't need to verify the email address.
Tap Settings > iCloud. Complete these steps only if the Find My [Device] setting is turned on:
Scroll down and tap Sign Out, then tap Sign Out to confirm. If you're using iOS 7 or earlier, tap Delete Account, then tap Delete to confirm.
Tap Keep on My [Device] or Delete from My [Device]. In either case, your data remains in iCloud and will be updated on your device when you sign in to iCloud again.
Enter the password for your previous Apple ID.
Change your Apple ID to the new email address that you want to use. You'll need to verify the email address.
Return to Settings > iCloud and sign in with your new Apple ID.
If you're still asked for your previous Apple ID password, continue to the next step.
Have a great day,
Joe -
ORA-01776: cannot modify more than one base table through a join view
I have created EO based on a database view than consists of two tables, and only one is updateable.
When I try to update a row using EO, I got a following message: "ORA-01776-cannot modify more than one base table through a join view"
In Forms, this issue is resolved by setting "Query Only" property of non-updateable items to "True".
Is it possible to do something like that in ADF BC?
ThanksThanks for answer.
When I set "updateable" property to "Never", that attribute is protected from any change.
I'm sorry for incomplete usecase.
I have set up a list of value on that attribute, because it is a lookup field for another table and I need to get an ID from that table.
Basically, I need that attribute to be updateble for BC, but not for database.
Edited by: MarioK on Oct 13, 2011 9:28 AM -
Cannot modify more than one base table through a join view
hi guys, my current problem is that i have a datablock based on a view, now all the fields bar 1 are updateable, but this one field that is obtained through a join is displayed, the user can enter data in this field which then pupulates other fields which are required, but this specific field should not be updated. Is there an option to state this as i keep getting the error:
cannot modify more than one base table through a join view
Any help would be greatly appreciated, thanks.the user can enter data in this field which then pupulates other fields So, using the value of "this field" you then query the rest of the fields? Can you show us the code you use to populate the rest of the fields?
but this specific field should not be updatedHave you tried setting the "Query Only" property of the field to "Yes" and the other DML properties (Ins, Upd, Del) to No?
Also, what is your Forms version?
Thanks,
Craig B-)
If someone's response is helpful or correct, please mark it accordingly. -
How just return one row of a one to many join..
So I have a one to many join where the SMOPERATOR table has data I need however it has a couple of rows that match the JOIN condition in there. I just need to return one row. I think this can be accomplished with a subquery in the join however have not been able to come up with the right syntax to do so.
So:
SELECT "NUMBER" as danumber,
NAME,
SMINCREQ.ASSIGNMENT,
SMOPERATOR.PRIMARY_ASSIGNMENT_GROUP,
SMOPERATOR.WDMANAGERNAME,
SMINCREQ.owner_manager_name,
SMINCREQ.subcategory, TO_DATE('01-'||TO_CHAR(open_time,'MM-YYYY'),'DD-MM-YYYY')MONTHSORT,
(CASE WHEN bc_request='f' THEN 'IAIO'
WHEN (bc_request='t' and substr(assignment,1,3)<>'MTS') THEN 'RARO'
WHEN (bc_request='t' and substr(assignment,1,3)='MTS') THEN 'M'
ELSE 'U' end) as type
from SMINCREQ
left outer join SMOPERATOR on SMINCREQ.assignment=SMOPERATOR.primary_assignment_group
WHERE SMINCREQ.owner_manager_name=:P170_SELECTION and SMOPERATOR.wdmanagername=:P170_SELECTION
AND open_time BETWEEN to_date(:P170_SDATEB,'DD-MON-YYYY') AND to_date(:P170_EDATEB,'DD-MON-YYYY')
AND
(bc_request='f' and subcategory='ACTIVATION' and related_record<>'t')
OR
(bc_request='f' and subcategory<>'ACTIVATION')
OR
(bc_request='t' and substr(assignment,1,3)<>'MTS')
order by OPEN_TIMeHi,
This sounds like a Top-N Query , where you pick N items (N=1 in this case) off the top of an orderded list. I think you want a separate ordered list for each assignment; the analytic ROW_NUMBER function does that easily.
Since you didn't post CREATE TABLE and INSERT statements for your sample data, I'll use tables from the scott schema to show how this is done.
Say you have a query like this:
SELECT d.dname
, e.empno, e.ename, e.job, e.sal
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
ORDER BY dname
;which produces this output:
DNAME EMPNO ENAME JOB SAL
ACCOUNTING 7934 MILLER CLERK 1300
ACCOUNTING 7839 KING PRESIDENT 5000
ACCOUNTING 7782 CLARK MANAGER 2450
RESEARCH 7876 ADAMS CLERK 1100
RESEARCH 7902 FORD ANALYST 3000
RESEARCH 7566 JONES MANAGER 2975
RESEARCH 7369 SMITH CLERK 800
RESEARCH 7788 SCOTT ANALYST 3000
SALES 7521 WARD SALESMAN 1250
SALES 7844 TURNER SALESMAN 1500
SALES 7499 ALLEN SALESMAN 1600
SALES 7900 JAMES CLERK 950
SALES 7698 BLAKE MANAGER 2850
SALES 7654 MARTIN SALESMAN 1250Now say you want to change the query so that it only returns one row per department, like this:
DNAME EMPNO ENAME JOB SAL
ACCOUNTING 7782 CLARK MANAGER 2450
RESEARCH 7876 ADAMS CLERK 1100
SALES 7499 ALLEN SALESMAN 1600where the empno, ename, job and sal columns on each row of output are all taken from the same row of scott.emp, though it doesn't really matter which row that is.
One way to do it is to use the analytic ROW_NUMBER function to assign a sequence of unique numbers (1, 2, 3, ...) to all the rows in each department. Since each sequence startw with 1, and the numbers are unique within a department, there will be exactly one row per departement that was assigned the numebr 1, and we''ll display that row.
Here's how to code that:
WITH got_r_num AS
SELECT d.dname
, e.empno, e.ename, e.job, e.sal
, ROW_NUMBER () OVER ( PARTITION BY d.dname
ORDER BY e.ename
) AS r_num
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
SELECT dname
, empno, ename, job, sal
FROM got_r_num
WHERE r_num = 1
ORDER BY dname
;Notice that he sub-query got_r_num is almost the same as the original query; only it has one additional column, r_num, in the SELECT clause, and the sub-qeury does not have an ORDER BY clause. (Sub-queries almost never have an ORDER BY clause.)
The ROW_NUMBER function must have an ORDER BY clause. In this example, I used "ORDER BY ename", meaning that, within each department, the row with the first ename (in sort order) will get r_num=1. You can use any column, or expression, or expressions in the ORDER BY clause. You muight as well use something consistent and predictable, like ename, but if you really wanted arbitrary numbering you could use a constant in the analytic ORDER BY clause, e.g. "ORDER BY NULL". -
One-to-Many implemented with a join Table
Hello,
Is it possible to implement a One-to-Many relationship with a join table, just like
the Reference Implementation does.
Regards,
Jeroen"Jeroen Ferdinandus" <[email protected]> wrote in
news:[email protected]:
Is it possible to implement a One-to-Many relationship with a join
table, just like the Reference Implementation does.Not with our CMP, you will have to resort to BMP for that.
Cedric -
Unidirectional one-to-many relationship without a join table
Hello,
I have 2 classes, Invoice and InvoiceLine, and a one-to-many unidirectional relationship from Invoice to InvoiceLine. By default, with JPA, it would be mapped by a join table with foreign keys that refer to the 2 tables which represent Invoice and InvoiceLine.
My problem: the database has already a foreign key in the table which represents InvoiceLine that refers to the table which represents Invoice.
To solve my problem I could make the relationship bidirectional but I would like to know if it is possible to keep it unidirectional and to use the foreign key which already exists (in the table that represents InvoiceLine). How could I declare the mapping with JPA?
Thanks in avance for your answers.JPA requires that any @OneToMany mapping not using a join table have an inverse @ManyToOne mapping. In general the foreign key in the target object needs to be mapped and a @ManyToOne mapping is normally the best way to map it, so making the relationship bi-directional is your best option.
There are other ways in TopLink to map a unidirectional 1-m, but these are not directly supported by the JPA spec. You could define a TopLink OneToManyMapping for the relationship through a TopLink DescriptorCustomizer and the code API. You would still need to map the foreign key in the target object some way, but you could use a @Basic mapping for this as long as you keep it in synch.
In TopLink you could also map the relationship using an AggregateCollectionMapping (basically a collection of embeddables), and then not require mapping the foreign key in the target, but this imposes limitations on the target object (must be treated like an embeddable instead of entity). You would also need to configure the target object to be an aggregateCollectionDescriptor if using this option. -
Messy One to Many Joins and Grouping
I manage websites for a large state agency in Texas. I have a
need to redo
queries that list the Local intake numbers for Long term
support services
(LTSS), Area Agencies on Aging (AAA), and Mental Retardation
Authorities
(MRA) by county for each of the state's 254 counties -- in
the past there
was only one intake number per county for each AAA and MRA,
with there being
the possibility for multiple LTSS intake numbers. Now there
are counties
that have multiple numbers for MRA intake.
Basic Structure of Database Tables:
CountyCenter Table
County (text)
CountyNumber (integer)
AAA_ID (integer)
MRA_ID (integer)
LTSS Table
County (text)
CountyNumber (integer)
City (text) -- optional used when there are multiple offices
for a county
IntakeNumber (text)
Region (text)
AAA Table
AAA_ID (integer)
AAAName (text)
AAAPhone (text)
MRA Table
MRA_ID (integer)
MRAName (text)
MRAPhone
MRAOffices
MRA_ID (integer)
IntakePhone (text)
City (Text)
CountyNumber (integer)
My goal is for each county to list in a combined table:
Column 1 = County Name
Column 2 = LTSS Office (Number(s))
Column 3 = MRA Intake Number
Column 4 = AAA Intake Number(s)/City if not main
Do I need a separate table for county that simply has the
CountyNumber and
CountyName to use as a control table?
I'd like to do this as efficiently as possible -- thankfully
the query won't
be accessed by the general public and will be run only when
updated
information is received. Any suggestions as to order of the
joins and
groupings in CFOUTPUT? (what I have now creates a lot of
duplication)
Thanks in advance for your help,
Michael Brown
Webmaster, Texas Department of Aging and Disability ServicesPhil,
Thanks for taking a look. You're definitely right. The data
structures are a mess. What was originally intended to be on
three
separate pages has been requested to be "available at a
glance."
With both the LTSS Offices and MRAs having the possiblity of
multiple offices for a given county what would be the best
way to
normalize the data? The tables for MRA, AAA, and LTSS have
CountyNumber (county exists only in those tables to provide
context for those who update the information manually (not my
choice/decision)).
So to break it down 254 Counties, each can have one or
multiple
LTSS numbers (and the number's city), only one AAA number,
and one
MRA with the possiblity for multiple intake numbers (and note
containing location information).
Hopefully, there is a graceful way of getting the output the
way
it has been requested. I'm open to suggestions.
Thanks again,
Michael
"paross1" <[email protected]> wrote in
news:[email protected]:
> After taking a quick glance, it looks like you already
have
> normalization issues with your data model, since LTSS
Table and
> CountyCenter Table both contain County (text), and
MRAOffices
and LTSS
> Table both have City (text), etc. It is hard to tell
which
fields are
> primary keys and which are foreign keys to which tables.
Some of
these
> that may have a one-to-many relationship that now
changes to a
> many-to-many will require a link table (associative
entity) and
the
> foreign keys migrated to them.
>
> You need to resist creating actual "combined tables",
spreadsheet
> style, and
> instead normalize your database, so that you can create
your
"combined
> table" virtually using SQL. It is hard to offer
specifics, since
I
> would need more information to do so, but the bottom
line is
that you
> do have some obvious data model issues that need to be
resolved
before
> you can get much further. Otherwise, you are going to
have to
write
> some very kludgey SQL to solve your problem with your
current
model.
>
> Phil
>
> -
How to resolve many-to-many join by 2 one-to-many joins
Hi,
I was asked many times how to resolve many to many relationship between two tables. I read to use 2 one -to- many relationships to resolve this. Can some expalin me when many to many relationship occurs between two tables and how to reslove them with practicle examples. Is there any article on this?
Regards,
Nanda KishoreHi,
Please check below link.
http://www.forumtopics.com/busobj/viewtopic.php?p=859029&sid=20d79e3df07b0d8b41aadfbd902bb6b2
http://blog.oaktonsoftware.com/2011/04/bridge-tables-and-many-to-many.html
Thanks,
Amit -
How do I create a One to many relationship page in Dreamweaver?
How do I create a page in dreamweaver that comes up after the user logs in from the log in page that will allow the user to:
Add, change and delete in 2 tables that are in my MYSQL database that is a one to many relationship
One thing that is confusing is how the foreign key that links to the one side of the relationship is created in the many side without the user inputting the foreign key each time adding information to the many side table.
I am creating this in Dreamweaver using a MYSQL database and PHP.>Would the following be a part of it:
>
>Outer join
Probably not. When updating/inserting/deleting from 2 tables you perform each seperately. Table updates may join two or more tables to resolve the correct row(s) but you still only update one table at a time. Procedurally you would create a transaction, update the first table, update the second table and then commit the transaction.
EDIT: Well I take back my last comment. I see that MySQL does seem to support multiple table updates. I don't use MySQL so I can't really help you on that but the MySQL manual gives pretty clear syntax. -
One-to-many/foreign keys howto
I have a situation where I'm trying to assemble a web of data and not make
JDO mad.
Here's the structure. I load this data in in batches, with an entry being
placed in a load history table (H) to track each batch. Each batch
contains primary (M) records associated with 0..n qualifying records from
one or both of two auxiliary tables (D, L). All liberally salted with
primary and foreign keys for referential integrity, and most of the keys
are compounds, since the "M" identifiers get recycled for each batch load.
Or, in other words, the "M" key is an ID plus an H key.
Here's a map:
H--0..n-->M
__ +--0..n-->D
__ +--0..n-->L
Just to make things even more fun, the primary key of the H table is an
Oracle 8 "DATE" type, which -- unlike ANSI SQL -- is actually a
"TIMESTAMP". Kodo is rendering this as a java.util.Date rather than
java.sql.Date, which is fine, because I need the full millisecond
resolution. Interestingly, when I altered the schema type to "timestamp",
load operations failed because the "column value was too big" according to
Oracle.
Also adding to the enjoyment, the actual order of presentation of data is
that ALL M records come in, then ALL D records and finally ALL L records.
I create my own H when the load starts.
Now ideally, the whole shooting match will be a single pass/fail
transaction, but that's for later.
Right now, I can create the H, no problem and M's no problem. However,
adding the D's and L's fails come commit time:
kodo.util.FatalUserException: Attempt to set column "OFAC_ADDRESS.LOAD_ID"
to two different values: "7/9/04 9:41 AM", "7/9/04 9:41 AM" This can occur
when you fail to set both sides of a two-sided relation between objects,
or when you map different fields to the same column, but you do not keep
the values of these fields in synch.
The granularity of the timestamps printed isn't making life easier, so I
double-checked the D record's actual local value
ADDRESS SERIALIZER A: Fri Jul 09 09:41:58 EDT 2004/Fri Jul 09 09:41:58 EDT
2004
ADDRESS SERIALIZER B: 1089380518179/1089380518179 (getTime())
ADDRESS SERIALIZER C: -1541174818/-1541174818 (hashCode())
I think I need a clearer understanding of what actions cascade here and
what actions require manual help. For M, I did a setH(H) plus a
setHid(H.getId()) and that made it happy. For D's and L's, of course, I
also have to do a setM(M), where, because of the way the data comes in, I
had to lookup the previously-stored M based on the M.id plus H.id.
Now the parent objects contain sets of child objects. In theory, I should
be adding the newly-created children to those sets, but in practice,
setting the parent on the child appears to cause this to happen
automagically, though I still have to manually set the local value of the
foreign key field.
I really need to find a good FM to RT. Online (and in the Kodo docs), I
find a lot about setting up the XML for one-to-many mapping, but the Java
coding side is taken as obvious. Regrettably, few things are obvious to me.
I suppose I should excerpt the schema just for completeness:
<table name="LOAD_HISTORY">
<pk name="SYS_C0036906" column="LOAD_ID"/>
<column name="LIST_TYPE" type="varchar" size="32"/>
<column name="LOADED_BY" type="varchar" size="32"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="SUNSET_TIME" type="date" size="7"/>
<fk name="FK_LOADHISTORY_LOADEDBY" delete-action="exception"
to-table="OFAC.OFAC_USERS" column="LOADED_BY"/>
</table>
<table name="OFAC_ADDRESS">
<pk name="SYS_C0036904">
<on column="ADDRESS_ID"/>
<on column="LOAD_ID"/>
</pk>
<column name="ADDRESS" type="varchar" size="125"/>
<column name="ADDRESS_ID" type="decimal" not-null="true"
size="22"/>
<column name="CITY" type="varchar" size="64"/>
<column name="COUNTRY" type="varchar" size="64"/>
<column name="ID" type="decimal" size="22"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="REMARKS" type="varchar" size="300"/>
<fk name="FK_OFACADDRESS_ID" delete-action="exception"
to-table="OFAC.OFAC_MAIN">
<join column="ID" to-column="ID"/>
<join column="LOAD_ID" to-column="LOAD_ID"/>
</fk>
<fk name="FK_OFACADDRESS_LOADID" delete-action="exception"
to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
</table>
<table name="OFAC_ALIAS">
<pk name="SYS_C0036905">
<on column="ALIAS_ID"/>
<on column="LOAD_ID"/>
</pk>
<column name="ALIAS" type="varchar" size="200"/>
<column name="ALIAS_ID" type="decimal" not-null="true"
size="22"/>
<column name="ID" type="decimal" size="22"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="REMARKS" type="varchar" size="300"/>
<fk name="FK_OFACALIAS_ID" delete-action="exception"
to-table="OFAC.OFAC_MAIN">
<join column="ID" to-column="ID"/>
<join column="LOAD_ID" to-column="LOAD_ID"/>
</fk>
<fk name="FK_OFACALIAS_LOADID" delete-action="exception"
to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
</table>
<table name="OFAC_MAIN">
<pk name="SYS_C0036903">
<on column="ID"/>
<on column="LOAD_ID"/>
</pk>
<column name="ID" type="decimal" not-null="true" size="22"/>
<column name="LOAD_ID" type="date" not-null="true" size="7"/>
<column name="REMARKS" type="varchar" size="300"/>
<fk name="FK_OFACMAIN_LOADID" delete-action="exception"
to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
</table>Hi Greg,
I'm just using the unmodified schema-to-mapping output. The one thing that
might be unusual is that I've broken up related tables into discrete
packages, but I believe all the items in question are in this package.
Here it is:
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
<package name="com.everbank.finance.ofac3.jdo.sdn">
<class name="LoadHistory">
<jdbc-class-map type="base" table="OFAC.LOAD_HISTORY"/>
<jdbc-version-ind type="state-image"/>
<field name="listType">
<jdbc-field-map type="value" column="LIST_TYPE"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="ofacAddress">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ADDRESS"/>
</field>
<field name="ofacAlias">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ALIAS"/>
</field>
<field name="ofacMains">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_MAIN"/>
</field>
<field name="ofacUsers">
<jdbc-field-map type="one-one" column.USER_ID="LOADED_BY"/>
</field>
<field name="runInfoLoadIdents">
<jdbc-field-map type="one-many"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.RUN_INFO_LOAD_ID"/>
</field>
<field name="sunsetTime">
<jdbc-field-map type="value" column="SUNSET_TIME"/>
</field>
</class>
<class name="OfacAddress">
<jdbc-class-map type="base" table="OFAC.OFAC_ADDRESS"/>
<jdbc-version-ind type="state-image"/>
<field name="address">
<jdbc-field-map type="value" column="ADDRESS"/>
</field>
<field name="addressId">
<jdbc-field-map type="value" column="ADDRESS_ID"/>
</field>
<field name="addressMp1">
<jdbc-field-map type="value" column="ADDRESS_MP1"/>
</field>
<field name="addressMp2">
<jdbc-field-map type="value" column="ADDRESS_MP2"/>
</field>
<field name="city">
<jdbc-field-map type="value" column="CITY"/>
</field>
<field name="cityMp1">
<jdbc-field-map type="value" column="CITY_MP1"/>
</field>
<field name="cityMp2">
<jdbc-field-map type="value" column="CITY_MP2"/>
</field>
<field name="country">
<jdbc-field-map type="value" column="COUNTRY"/>
</field>
<field name="countryMp1">
<jdbc-field-map type="value" column="COUNTRY_MP1"/>
</field>
<field name="countryMp2">
<jdbc-field-map type="value" column="COUNTRY_MP2"/>
</field>
<field name="loadHistory">
<jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="ofacMain">
<jdbc-field-map type="one-one" column.ID="ID"
column.LOAD_ID="LOAD_ID"/>
</field>
<field name="remarks">
<jdbc-field-map type="value" column="REMARKS"/>
</field>
</class>
<class name="OfacAlias">
<jdbc-class-map type="base" table="OFAC.OFAC_ALIAS"/>
<jdbc-version-ind type="state-image"/>
<field name="alias">
<jdbc-field-map type="value" column="ALIAS"/>
</field>
<field name="aliasId">
<jdbc-field-map type="value" column="ALIAS_ID"/>
</field>
<field name="aliasMp1">
<jdbc-field-map type="value" column="ALIAS_MP1"/>
</field>
<field name="aliasMp2">
<jdbc-field-map type="value" column="ALIAS_MP2"/>
</field>
<field name="aliasType">
<jdbc-field-map type="value" column="ALIAS_TYPE"/>
</field>
<field name="loadHistory">
<jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="ofacMain">
<jdbc-field-map type="one-one" column.ID="ID"
column.LOAD_ID="LOAD_ID"/>
</field>
<field name="remarks">
<jdbc-field-map type="value" column="REMARKS"/>
</field>
</class>
<class name="OfacMain">
<jdbc-class-map type="base" table="OFAC.OFAC_MAIN"/>
<jdbc-version-ind type="state-image"/>
<field name="callSign">
<jdbc-field-map type="value" column="CALL_SIGN"/>
</field>
<field name="callSignMp1">
<jdbc-field-map type="value" column="CALL_SIGN_MP1"/>
</field>
<field name="callSignMp2">
<jdbc-field-map type="value" column="CALL_SIGN_MP2"/>
</field>
<field name="grt">
<jdbc-field-map type="value" column="GRT"/>
</field>
<field name="id">
<jdbc-field-map type="value" column="ID"/>
</field>
<field name="loadHistory">
<jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
</field>
<field name="loadId">
<jdbc-field-map type="value" column="LOAD_ID"/>
</field>
<field name="matchInfos">
<jdbc-field-map type="one-many" ref-column.ID="ID"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.MATCH_INFO"/>
</field>
<field name="ofacAddress">
<jdbc-field-map type="one-many" ref-column.ID="ID"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ADDRESS"/>
</field>
<field name="ofacAlias">
<jdbc-field-map type="one-many" ref-column.ID="ID"
ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ALIAS"/>
</field>
<field name="pName">
<jdbc-field-map type="value" column="P_NAME"/>
</field>
<field name="pNameMp1">
<jdbc-field-map type="value" column="P_NAME_MP1"/>
</field>
<field name="pNameMp2">
<jdbc-field-map type="value" column="P_NAME_MP2"/>
</field>
<field name="program">
<jdbc-field-map type="value" column="PROGRAM"/>
</field>
<field name="remarks">
<jdbc-field-map type="value" column="REMARKS"/>
</field>
<field name="sName">
<jdbc-field-map type="value" column="S_NAME"/>
</field>
<field name="sNameMp1">
<jdbc-field-map type="value" column="S_NAME_MP1"/>
</field>
<field name="sNameMp2">
<jdbc-field-map type="value" column="S_NAME_MP2"/>
</field>
<field name="sdnType">
<jdbc-field-map type="value" column="SDN_TYPE"/>
</field>
<field name="ssn">
<jdbc-field-map type="value" column="SSN"/>
</field>
<field name="title">
<jdbc-field-map type="value" column="TITLE"/>
</field>
<field name="tonnage">
<jdbc-field-map type="value" column="TONNAGE"/>
</field>
<field name="vesselFlag">
<jdbc-field-map type="value" column="VESSEL_FLAG"/>
</field>
<field name="vesselOwner">
<jdbc-field-map type="value" column="VESSEL_OWNER"/>
</field>
<field name="vesselOwnerMp1">
<jdbc-field-map type="value" column="VESSEL_OWNER_MP1"/>
</field>
<field name="vesselOwnerMp2">
<jdbc-field-map type="value" column="VESSEL_OWNER_MP2"/>
</field>
<field name="vesselType">
<jdbc-field-map type="value" column="VESSEL_TYPE"/>
</field>
</class>
</package>
</mapping>
Als, just for giggles, the JDO file
<?xml version="1.0" encoding="UTF-8"?>
<jdo>
<package name="com.everbank.finance.ofac3.jdo.sdn">
<class name="LoadHistory"
objectid-class="com.everbank.finance.ofac3.jdo.LoadHistoryId">
<field name="loadId" primary-key="true"/>
<field name="ofacAddress">
<collection element-type="OfacAddress"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
<field name="ofacAlias">
<collection element-type="OfacAlias"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
<field name="ofacMains">
<collection element-type="OfacMain"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
<field name="runInfoLoadIdents">
<collection
element-type="com.everbank.finance.ofac3.jdo.match.RunInfoLoadIdent"/>
<extension vendor-name="kodo" key="inverse-owner"
value="loadHistory"/>
</field>
</class>
<class name="OfacAddress"
objectid-class="com.everbank.finance.ofac3.jdo.OfacAddressId">
<field name="addressId" primary-key="true"/>
<field name="loadId" primary-key="true"/>
</class>
<class name="OfacAlias"
objectid-class="com.everbank.finance.ofac3.jdo.OfacAliasId">
<field name="aliasId" primary-key="true"/>
<field name="loadId" primary-key="true"/>
</class>
<class name="OfacMain"
objectid-class="com.everbank.finance.ofac3.jdo.OfacMainId">
<field name="id" primary-key="true"/>
<field name="loadId" primary-key="true"/>
<field name="matchInfos">
<collection
element-type="com.everbank.finance.ofac3.jdo.match.MatchInfo"/>
<extension vendor-name="kodo" key="inverse-owner"
value="ofacMain"/>
</field>
<field name="ofacAddress">
<collection element-type="OfacAddress"/>
<extension vendor-name="kodo" key="inverse-owner"
value="ofacMain"/>
</field>
<field name="ofacAlias">
<collection element-type="OfacAlias"/>
<extension vendor-name="kodo" key="inverse-owner"
value="ofacMain"/>
</field>
</class>
</package>
Greg Campbell wrote:
Hi Tim,
Could you send the your mapping information corresponding to the class that
maps to table: OFAC_ADDRESS. In particular, I'm looking for what fields
map to OFAC_ADDRESS.LOAD_ID. This will hopefully give us a hint as to
what's going wrong.
Thanks,
Greg
"Tim Holloway" <[email protected]> wrote in message
news:[email protected]...
I have a situation where I'm trying to assemble a web of data and not make
JDO mad.
<snipped> -
Help with multi-table mapping for one-to-many object inheritance
Hi,
I have posted on here before regarding this (Toplink mapping for one-to-many object inheritance but I am still having problems mapping my object model to my schema.
Object model
The Person and Organisation objects contain base information and have the primary keys person_id and organisation_id. It is important that there is no duplication of person and organisation records, no matter how many times they are saved in different roles.
There are two types of licenceholder in the problem domain, and the ILicenceHolder interface defines information and methods that are common to both. The PersonalLicenceHolder object represents one of these types of licenceholder, and is always a person, so this class extends Person and implements ILicenceHolder.
The additional information and methods that are required by the second type of licenceholder are defined in the interface IPremisesLicenceHolder, which extends ILicenceHolder. Premises licence holders can either be people or organisations, so I have two objects to represent these - PremisesLicenceHolderPerson which implements IPremisesLicenceHolder and extends Person, and PremisesLicenceHolderOrganisation which implements IPremisesLicenceHolder and extends Organisation.
The model is further complicated by the fact that any single Person may be both a PersonalLicenceHolder and a PremisesLicenceHolderPerson, and may be so several times over. In this case, the same basic Person information needs to be linked to several different sets of licenceholder information. In the same way, any single Organisation may be a PremisesLicenceHolderOrganisation several times over.
Sorry this is complicated!
Schema
I have Person and Organisation tables containing the basic information with the primary keys person_id and organisation_id.
I have tried to follow Donald Smith's advice and have created a Role table to record the specialised information for the different types of licence holder. I want the foreign keys in this table to be licenceholder_id and licence_id. Licenceholder_id will reference either organisation_id or person_id, and licence_id will reference the primary key of the Licence table to link the licenceholder to the licence. Because I am struggling with the mapping, I have changed licenceholder_id to person_id in an attempt to get it working with the Person object before I try the Organisation.
Then, when a new licenceholder is added, if the person/organisation is already in the database, a new record is created in the Role table linking the existing person/organisation to the existing licence rather than duplicating the person/organisation information.
Mapping
I am trying to use the toplink mapping workbench to map my PremisesLicenceHolderPerson object to my schema. I have mapped all inherited attributes to superclass (Person). The primary table that the attributes are mapped to is Person, and I have used the multi-table info tab to add Roles as an additional table and map the remaining attributes to that.
I have created the references PERSON_ROLES which maps person.person_id to roles.person_id, ROLES_PERSON which maps roles.person_id to person.person_id and ROLES_LICENCE which maps roles.licence_id to licence.licence_id.
I think I have put in all the relationships, but I cannot get rid of the error message "The following primary key fields are unmapped: PERSON_ID".
Please can somebody tell me how to map this properly?
Thank you.I'm not positive about your mappings, but it looks like the Person object should really have a 1:M or M:M mapping to the Licenceholder table. This then means that your object model should be similar, in that Person object could have many Licenses, instead of being LicenceHolders. From the looks of it, you have it set up from the LicenceHolder perspective. What could be done instead if a LicenceHolder could have a 1:1 reference to a person data object, rather than actually be a Person. This would allow the person data to be easily shared among licences.
LicenceHolder1 has an entry in the LicenceHolder table and Person table. LicenceHolder2 also has entries in these tables, but uses the same entry in the Person table- essentially it is the same person/person_ID. If both are new objects, TopLink would try to insert the same person object into the Person table twice. I'm not sure how you have gotten around or are planning to get around this problem.
Since you are using inheritance, it means that LicenceHolder needs a writable mapping to the person.person_id field- most commonly done through a direct to field mapping. From the description, it looks like roles.person_id is a foreign key in the multiple table mapping, meaning it would be set based on the value in the person.person_id field, but the person.person_id isn't actually mapped in the object. Check to make sure that the ID attribute LicenceHolder is inheriting from person hasn't been remapped in the LicenceHolder descriptor to a different field.
Best Regards,
Chris
Maybe you are looking for
-
How can I track where the customer has been directed to fill my form?
I have published a link for my forms on different websites like facebook, twitter, own website etc and was wondering that if there is any way adobe provides a platform to track the website which is been filled by the user was redirected from? This is
-
Hi all i have a pdf that i generate with FOP then i want to print it in silent mode.I have try the FOAWTRenderer,PDFBox and the basic javax.print but the results are very far from the Acrobat or Foxit print. Any idea for this problem? Thanks
-
Content copier backup has contacts etc. but won't ...
I have a problem with Content Copier backups from my E71 to my PC. 1) I choose to backup everything. 2) Backup proceeds, but says there was an error: on viewing logs there is nothing listed under "These items could not be backed up" heading. Backup l
-
Does anyone get a black screen after dismissing the balance on a paygo phone
I get a blank, black, screen after dismissing the balance on my paygo 3GS iphone. To get rid of it I put the phone into standby and then wake it up!
-
WRT300N VPN setup through hardware help please
Hello, I am trying to set up a VPN from one of my offices to another. I have a Linksys WRT300N router. I want to do it through hardwear and not through software. Can this be done with this specific routher? If so can someone walk me through how t