Referential integrity & bc4j createRow
Hi,
Okay, so I am aware that when I'm trying to add a new row to a table which has a foreign key to another table, I have to do something like this is order to make the create a new row work:
ViewLink viewLink = myAppModule.useApplicationModule().findViewLink("CvalidLink");
ViewObject viewObject = viewLink.getDestination();
Row newRow = viewObject.createRow();
So, what I still can't understand, even after scrounging the forums here, is what do I do if my table has TWO (as it happens, it's actually three) foreign keys to two different tables? I can comment the associations out, but rather than doing that, I'd like to find out if there's a real solution.
I noticed there's a method supposedly inherited by ViewObject called "createAndInitRow(AttributeList)" ... But it seems to deny it exists; I'm able to get that to work.
Any thoughts? I appreciate any assistance.
~T
You can have multiple masters to one detail VO in an AM.
To do so, bring up the AM's data model wizard.
Select the 1st master VO. Shuttle (thru the '>' button) it over to the righthand side.
Select the detail VO. While the master VO on the righthand side ('Data Model' tree) is selected, shuttle it over. This detail VO goes underneath the 1st master VO. You have something that looks more or less like:
+ FirstMasterVO
+-- DetailVO via MyViewLink
Now, shuttle your 2nd master VO.
While the 2nd master VO is selected in the 'Data Model' tree, select your detail underneath 2nd master VO in the 'Available View Objects' tree. Make sure that the name that appears in the lefthand text box matches the name of the detail VO under the 1st VO ('DetailVO' in the tree diagram above). Shuttle it.
A question will come up asking whether to the same instance or not. Say yes. This should result in the following struct in the 'Data Model' tree:
+ FirstMasterVO
+-- DetailVO via MyViewLink
+ SecondMasterVO
+-- DetailVO via MyOtherViewLink
The important thing is that the names that appear under FirstMasterVO and SecondMasterVO are the same.
Then, you can navigate FirstMasterVO and SecondMasterVO to desired rows. Then, call
ViewObject detailVO = myAM.findViewObject("DetailVO");
Row newRow = deatilVO.createRow().
This newRow will receive the two FK values from the two master VOs.
Thanks.
Sung
Similar Messages
-
Issue with Referential Integrity check in Oracle VPD Policy
Hi,
Lets assume I have two tables - Customer and Order, with cust_id in Order table referring to primary key of Customer table.
Example Data;
Customer
cust_id Name
1 abc
2 def
3 ghi
Order
Order_id cust_id Order_type
1 1 A
2 2 A
3 1 B
Now I have policies defined on both the tables;
- for "Select, Insert, Update" queries on Customer table.
- for "Select" queries on Order Table.
Policy 1 on Order Table;
Irrespective of the user, predicate = 'Order_type = ''A'''
Policy 2 on Customer Table;
Irrespective of the user, predicate = '(select count(1) from order o where o.cust_id = customer.cust_id and o.order_type = ''B'') > 0'
My intention is to show only those customers who have atleast one order of type 'B'. And this policy works fine in case a user tries to read data from customer table. (for example, record for cust_id = 2 will not be returned as it don't have any orders of type "B")
However, when a user tries to insert record in Order Table, because of the existing referential integrity constraint, the Policy on Customer table is also getting triggered. And an exception is being raised "ORA-28113: policy predicate has error".
Could someone please explain why this is happening ?I'm afraid, there is no such a mean.
At least I do not know about it. -
What is self referential integrity? How does it effect the Database?
Hello Gurus,
What is self referential integrity?
How could it is achieved and implemented?
and what is effect on the Database?
Thanks in advance.
~ SubbaReddy .MSelf referential integrity simple means that the parent end of a foreign key constraint is in the same table as the child end. Consider the SCOTT.EMP table. Every manager is also an employee. Hence there is a foreign key between the MGR column and the EMPNO column.
rgds, APC -
Maintaining referential integrity using MS SQL server
Some time ago I posted a question relating to the following extension:
<extension vendor-name="kodo" key="jdbc-delete-action" value="null"/>
Kodo generates a "on delete set null" constraint for this, however ms sql
server does not support this. Since I don't want to matain this referential
integrity in my java code (meaning as soon as an object is deleted, setting
all references to it to null), I tried to implement a custom dictionary with
the default ms sql server solution for this problem: creating a trigger by
overriding the "getAddForeignKeySQL" method. This works fine when creating a
database from scratch using the schema tool, however, when updating an
existing databasebase schema, this is ignored, thereby not solving the
problem of having the database maintenance automated. I suppose I have to
write code for checking whether the trigger already exists. Browsing through
the code, I couldn't figure out how this is done. Can someone give me
suggestions on how to do this (and if this takes a lot of effort).
I also would like to know whether solarmetric has intentions to deal with
this problem in their framework. To be honest, I was quite surprised that
Kodo doesnt take care of this, leaving my database in an inconsistent state.
kind regards,
Christiaan"Abe White" <[email protected]> schreef in bericht
news:caaunu$ecj$[email protected]..
>
I also would like to know whether solarmetric has intentions to dealwith
this problem in their framework. To be honest, I was quite surprisedthat
Kodo doesnt take care of this, leaving my database in an inconsistentstate.
>
Well, I would say that you're the one leaving the database in an
inconsistent state by not keeping your object model consistent :)From the manual:
6.2.2.12. jdbc-delete-action
If a field holds a relation to another object, you can use the
jdbc-delete-action field extension to control the delete action of the
database foreign key that models this relation. Possible values are:
null: Null the column(s) of this foreign key when the related record is
deleted.
It does mean that if the primary key record is deleted, all foreign keys to
the record are set to null, right? Since the jdo framework is about database
independence, not writing sql code (and of course lots more;) and Kodo
supports ms sql server, I would have expected that kodo to set the foreign
key to null if the object is deleted. Even if I do know sql server supports
does not support a 'on delete set null' sql statement;)
>
We have no plans to create triggers at this time.
What do you mean when you say "it is ignored" when you're updating?
Exactly what tool are you running, what actions are you running with, is
the foreign key extension present, and what is the outcome?Like I said, I wrote code in the "getAddForeignKeySQL" in the dictionary, so
a trigger is created when creating the database in the workbench (by running
the schematool). However, if the table already exists, but not the trigger,
refreshing the database from the workbench does not call the
getAddForeignKeySql to add the trigger to the table. -
I have been interested in how lightroom uses the catalog so was poking around a backup of the catalog. I am a database administrator and I found it rather concerning that although the database (catalog) is pretty well designed, there is no referential integrity defined or enforced. This is non-standard practice and could well be the source of corrupt catalogs I have seen many people complain about. I would strongly recommend the developers modify the catalog and adopt best practices if they want to improve the stability of Lightroom and the catalog.
I would imagine that data integrity is not enforced for performance reasons. In a closed environment like LR where the application has complete control over the data, enforcing data integrity may not be worth the performance hit. Often what is done in an environment like this is to have data integrity on in test environments which would expose data integrity bugs but where the impact of performance is low. In "production" it is then turned off to get as much performance as possible. I would say there are many more complaints about performance than corrupt catalogs. And corrupt catalogs are more likely due to interruptions in writing to the catalog (like crashes, backups or dropbox activity while LR is running, etc). Data integrity would not help in these cases as they are outside the databases control.
-
DRI (declarative referential integrity) and speed improvements.
EDITED: See my second post--in my testing, the relevant consideration is whether the parent table has a compound primary key or a single primary key. If the parent has a simple primary key, and there is a trusted (checked) DRI relation
with the child, and a query requests only records from the child on an inner join with the parent, then sql server (correctly) skips performing the join (shown in the execution plan). However, if the parent has a compound primary key, then sql server
performs a useless join between parent and child. tested on sql 2008 r2 and denali. If anyone can get sql server NOT to perform the join with compound primary keys on the parent, let me know.
ORIGINAL POST: I'm not seeing the join behavior in the execution plan given in the link provided (namely that the optimizer does not bother performing a join to the parent tbl when a query needs information from the child side only AND
trusted DRI exists between the tables AND the columns are defined as not null). The foreign key relation "is trusted" by Sql server ("is not trusted" is false), but the plan always picks both tables for the join although only one is needed.
If anyone has comments on whether declarative ref integrity does produce speed improvements on certain joins, please post. thanks.
http://dinesql.blogspot.com/2011/04/does-referential-integrity-improve.htmlI'm running sql denali ctp3 x64 and sql 2008 r2 x64, on windows 7 sp1. I've tested it on dozens of tables, and I defy anyone to provide a counter-example (you can create ANY parent table with two ints as a composite primary key, and then a child table using
that compound as a foreign key, and create a trusted dri link between them and use the above queries I posted)--any table with a compound foreign key relation as the basis for the DRI apparently does not benefit from referential integrity between those tables
(in terms of performance). Or to be more precise, the execution plan reveals that sql server performs a costly and unnecessary join in these cases, but not when the trusted DRI relation between them is a single primary key. If anyone has seen a different result,
please let me know, since it does influence my design decisions.
fwiw, a similar behavior is true of sql server's date correlation optimization: it doesn't work if the tables are joined by a composite key, only if they are a joined by a single column:
"There must be a single-column
foreign key relationship between the tables. "
So I speculate, knowing absolutely nothing, that there must be something deep in the bowels of the engine that doesn't optimize compound key relations as well as single column ones.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[parent](
[pId1] [int] NOT NULL,
[pId2] [int] NOT NULL,
CONSTRAINT [PK_parent] PRIMARY KEY CLUSTERED
[pId1] ASC,
[pId2] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Children](
[cId] [int] IDENTITY(1,1) NOT NULL,
[pid1] [int] NOT NULL,
[pid2] [int] NOT NULL,
CONSTRAINT [PK_Children] PRIMARY KEY CLUSTERED
[cId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Children] WITH CHECK ADD CONSTRAINT [FK_Children_TO_parent] FOREIGN KEY([pid1], [pid2])
REFERENCES [dbo].[parent] ([pId1], [pId2])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
/* the dri MUST be trusted to work, but it doesn't work anyway*/
ALTER TABLE [dbo].[Children] CHECK CONSTRAINT [FK_Children_TO_parent]
GO
/* Enter data in parent and children */
select c.cId FROM dbo.Children c INNER JOIN Parent p
ON p.pId1 = c.pId1 AND p.pId2 = c.pId2;
/* Execution plan will be blind to the trusted DRI--performs the join!*/ -
For some strange reason when I modified a form, (commented out some code in a when-window-activated trigger) I now get the following error.
CDG-01141 ERROR: Module Component Table Usage GR1130A.CUSTOMER.GR_CUSTOMER.GC: Table usage GR_CUSTOMER requires primary key column for referential integrity
I am sure this is not related to my change, but do not know what may have caused this or how to fix it.
Anyone seen this error before? been able to fix it?
Thanks!
Windows 7
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
Designer Version 6.5.95.4.8You know that Developer/Designer 6i is not certified for Windows 7, right? Also, your version is not the latest one, so you can try to install the latest patch set first.
>Table usage GR_CUSTOMER requires primary key column for referential integrity
Check if there is a PK in the table definition (not in the database, but in Designer). -
Self Referential integrity constraint?
What is self-referential integrity constraint? Is it a foreign key where the same column acts as the parent key too.
The good old EMP table in the SCOTT schema is one example. Managers are employees, so the MGR column refers back to the EMPNO primary key. If I wanted to create my own table...
1 create table emp2 (
2 empno number primary key,
3 mgr number references emp2( empno )
4* )
SCOTT @ hp92 Local> /
Table created.Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
What is mean by Referential Integrity? Where do we use it and Why..?
Hi All,
Can anybody tell me, What is mean by Referential Integrity? Where do we use it and Why..?
Regards,
Kiran TelkarDear Kiran Telkar ,
you might be knowing that generally refrential integrity is concerned with nothing but primary key and foriegn key relationship. Generally we use to check uniqueness of records.
In sap we use it during flexible updation...to check the data records of transaction data and master data.
In other words, to check before loading of data, that whether loading will be properly or not.
we will check(tick) the option in the maintainance of the
<b>infosource--> communication structure</b>
it will be better if you clearly mention your problem, if further help is needed.
hope this will help you.
Regards
vinay
<i>please assign points to all who will help you.</i> -
Query to display the tables with referential integrity
Hello,
I need to display the Tables which are having referential integrity..
Like need to dispaly the parent and child tables
Please give me some idea on this..
Thanks,Here's a nice query you can use:
with temp_constraints as (
select table_name
, constraint_name pkey_constraint
, null fkey_constraint
, null r_constraint_name
from user_constraints
where constraint_type = 'P'
union all
select a.table_name
, a.constraint_name pkey_constraint
, b.constraint_name fkey_constraint
, b.r_constraint_name
from user_constraints a, user_constraints b
where a.table_name = b.table_name
and a.constraint_type = 'P'
and b.constraint_type = 'R'
select rpad( '*', (level-1)*2, '*' ) || table_name relation
from temp_constraints
start with fkey_constraint is null
connect by pkey_constraint <> r_constraint_name
and prior pkey_constraint = r_constraint_name;From http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:661009003696#tom69115451356231 -
Tables with referential integrity
Hi All,
I am generating scripts to insert data from one schema to another. something like this:
Insert into schemaA.table1
select *from schemaB.table1;There are many tables with referential integrity in the schema. how can generate the scripts in an order so that there
won' t be any referential integrity issue....
Thanks.
AJRHi,
Thanks.
I tried, but it gives me 6 sets of data.
SELECT TABLE_NAME--, LTRIM(SYS_CONNECT_BY_PATH(TABLE_NAME, '=>'),'=>') TABLE_NAME_PATH,CONSTRAINT_NAME, R_CONSTRAINT_NAME, LEVEL
FROM USER_CONSTRAINTS,ALL_OBJECTS B
--WHERE LEVEL > 1
WHERE
USER_CONSTRAINTS.OWNER = B.OWNER AND
USER_CONSTRAINTS.TABLE_NAME = B.OBJECT_NAME AND
B.OBJECT_TYPE = 'TABLE'
CONNECT BY R_CONSTRAINT_NAME = PRIOR CONSTRAINT_NAME
ORDER BY TABLE_NAME;AJR -
Maintaining referential integrity
Hi,
How do I ensure that referential integrity is maintained when deleting rows from a table that has a primary key referenced in another table by a foreign key? Is there a way when creating the table (or by altering the table) to include a check for child records and delete child records at the same time of deleting the parent record?
thanksHi,
are you thinking about a cascading delete?
If yes, you can create a foreing key like this:
ALTER TABLE my_table ADD CONSTRAINT my_fk FOREIGN KEY
REFERENCES my_master_table(my_pk_column)
ON DELETE CASCADE:
This is a foreing key which allows to delete a parent record for which child records exist.
The child records will be deleted automatically.
If you do not want the child records to get deleted you can also choose:
ALTER TABLE my_table ADD CONSTRAINT my_fk FOREIGN KEY
REFERENCES my_master_table(my_pk_column)
ON DELETE SET NULL;
This will update the foreign keys to NULL.
Hope this helps,
Lutz -
How to export-import referential integrity constraints ?
Hi all
Is there any way to export only the referential integrity constraints from one user to another user ?
Suppose i am having SCOTT user which is having EMP , DEPT tables . And also I am having another user (say TEST) which also is having those EMP and DEPT table but without the referential integrity constraints . Now can i export
referential integrity constraints from SCOTT and import into TEST so that EMP,DEPT tables(in TEST) will have those referential integrity constraints which are present in SCOTT user ?
Thanks
Debashis
BangaloreHi,
See the BAM Enterprise Link Utilities User's Guide for additional Enterprise Link import/export capabilities not exposed via ICommand.
Regards, Stephen -
How to Check Referential Integrity for a field in Transformations.
Hi All,
We have a requirement where we need to check the referential integrity for a field in Transformation.
How can we Check Referential Integrity in Transformations?
Regards,
Rk.Hi,
you can check the referential integrity checkbox iis available in the transforamtaion there is a check box referential integrity from the source rules.
Thanks,
Ramesh. -
Referential integrity based on a view
Hi,
I am having difficulty in trying to build referential integrity based on a view.
I have explained below with an example:
I have a table called 'vehicles' which is the master table.
CREATE TABLE vehicles(
type VARCHAR2(20),
model_number NUMBER(5),
price NUMBER(5),
CONSTRAINT vehicles_pk PRIMARY KEY(type, model_number)
INSERT INTO vehicles(type, model_number, price) VALUES ('CAR', 1, 100);
INSERT INTO vehicles(type, model_number, price) VALUES ('BIKE', 1, 50);
INSERT INTO vehicles(type, model_number, price) VALUES ('CAR', 5, 200);
INSERT INTO vehicles(type, model_number, price) VALUES ('BIKE', 7, 50);
I have a view called 'vu_cars' which lists only the CAR from the table 'vehicles'.
CREATE VIEW vu_cars
AS
SELECT model_number
FROM vehicles
WHERE
type = 'CAR';
I have a table called 'car_properties' which contains the car properties and has referential integrity based on the view 'vu_cars'
-- This create statement throws an error, am I missing something ... ?
CREATE TABLE car_properties(
model_number VARCHAR2(20),
number_of_doors NUMBER(5),
PRIMARY KEY(model_number),
CONSTRAINT vu_cars_fk FOREIGN KEY (model_number) REFERENCES vu_cars(model_number)
-- Actually I wanted to execute the below insert statements, but am stuck with the above create statement of the table car_properties. Is there anyway to resolve this ?
--Below should be inserted correctly:
INSERT INTO car_properties(model_number, number_of_doors) VALUES (1, 4);
INSERT INTO car_properties(model_number, number_of_doors) VALUES (5, 2);
--This should throw an error:
INSERT INTO car_properties(model_number, number_of_doors) VALUES (7, 2);One approach would be to:
1. Add a TYPE column to CAR_PROPERTIES.
2. Add a check constraint on the TYPE column in CAR_PROPERTIES that requires it to equal 'CAR'.
3. Create a foreign key constraint on CAR_PROPERTIES referencing both MODEL_NUMBER and TYPE in VEHICLES. This requires a primary or unique constraint on these two columns in VEHICLES, but you already have one. However, both columns should have the same data type in both tables.
It might look something like this:
SQL> CREATE TABLE vehicles(
2 type VARCHAR2(20),
3 model_number NUMBER(5),
4 price NUMBER(5),
5 CONSTRAINT vehicles_pk PRIMARY KEY(type, model_number)
6 );
Table created.
SQL> INSERT INTO vehicles(type, model_number, price) VALUES ('CAR', 1, 100);
1 row created.
SQL> INSERT INTO vehicles(type, model_number, price) VALUES ('BIKE', 1, 50);
1 row created.
SQL> INSERT INTO vehicles(type, model_number, price) VALUES ('CAR', 5, 200);
1 row created.
SQL> INSERT INTO vehicles(type, model_number, price) VALUES ('BIKE', 7, 50);
1 row created.
SQL> CREATE TABLE car_properties(
2 -- Note new column with both not null and check constraint
3 type VARCHAR2(20) not null check (type = 'CAR'),
4 -- Note change in data type to be the same as vehicles table
5 model_number NUMBER(5) not null,
6 number_of_doors NUMBER(5),
7 PRIMARY KEY(model_number),
8 -- Note new constraint referencing vehicles table
9 CONSTRAINT vehicles_fk FOREIGN KEY (type, model_number) REFERENCES vehicles(type, model_number)
10 );
Table created.
SQL> INSERT INTO car_properties(type, model_number, number_of_doors) VALUES ('CAR', 1, 4);
1 row created.
SQL> INSERT INTO car_properties(type, model_number, number_of_doors) VALUES ('CAR', 5, 2);
1 row created.
SQL> INSERT INTO car_properties(type, model_number, number_of_doors) VALUES ('BIKE', 7, 2);
INSERT INTO car_properties(type, model_number, number_of_doors) VALUES ('BIKE', 7, 2)
ERROR at line 1:
ORA-02290: check constraint (TEMP.SYS_C0095831) violated
SQL> INSERT INTO car_properties(type, model_number, number_of_doors) VALUES ('CAR', 7, 2);
INSERT INTO car_properties(type, model_number, number_of_doors) VALUES ('CAR', 7, 2)
ERROR at line 1:
ORA-02291: integrity constraint (TEMP.VEHICLES_FK) violated - parent key not
found
SQL> INSERT INTO car_properties(type, model_number, number_of_doors) VALUES (NULL, 1, 4);
INSERT INTO car_properties(type, model_number, number_of_doors) VALUES (NULL, 1, 4)
ERROR at line 1:
ORA-01400: cannot insert NULL into ("TEMP"."CAR_PROPERTIES"."TYPE")Defining a default value for the TYPE column in CAR_PROPERTIES (to set it to 'CAR') might make this approach a little less obtrusive.
Maybe you are looking for
-
How in the world do i get my lost Album back? I purchased a Album from Itunes on my iphone, Played it for several days. Then when I synced my phone to my laptop, the album is no longer there. It shows up in the Itunes on my computer but only as the d
-
Class visibility problems in deployed OC4J application
I have an entity, autogenerated from a database table by JDeveloper, which has the form: Entity.java: package a.b.c; import ... @Entity @NamedQuery( ... ) @Table( ... ) public class Entity implements Serializable { @Column( ... ) : etc. }Then
-
Note 3 Lollipop - No Samsung App Store
What happened to the Samsung App Store or Galaxy App store or Galaxy Essentials or any other name. The point being that after the update i noticed i did not have an icon for the Samsung app store by whatever name they are using. Trying to find it m
-
Hello, With a brand-new MBP running 10.8.2 I'm experiencing freezes when trying to copy files in Finder. In this case I'm trying to transfer files from my iPod (as a storage device, copied from the iTunes folders on my old MBP; I need to get these on
-
PSE 9.0 unable to open organizer. App error (0xc0000005)
This problem began a few days ago. When I try to open the organizer I get the error message. I can open the editor and have tried to open the organizer from the editor with no luck. I have read alot of posts online from alot of others with the sam