Implement CASCADE Constraint Procedure?
Hi,
I need to delete records from some tables and its child tables. Currently cascade constraints is not allowed (don't know why?) and there is separate script which delete the records manually, like records are identified to be delete into a temp table and then with EXITS clause the records are deleted from child to parent.
I was wondering whether a recursive procedure will work which will delete records from child tables onwards to parent table. Is such a recursive procedure possible or i am wasting my time :(
If it's not possible then i'll have to stick with the script . . .
--procedure will have parent table as parameter and temp table with column on which delete is based
--cursor 1 will identify childs
cursor C_CHILD (P_USER varchar2, P_TABLE varchar2) is
SELECT table_name, constraint_name
FROM all_constraints
WHERE constraint_type ='R'
AND r_owner = P_USER
AND r_constraint_name IN
(SELECT constraint_name
FROM all_constraints
where CONSTRAINT_TYPE in ('P','U')
AND table_name = P_TABLE
--cursor 2 will identify columns to be joined (don't have the query yet)
BEGIN
FOR C_CHILD in c1
LOOP
EXIT WHEN C_CHILD%NOTFOUND
--call procedure again (recursive)
--delete based on columns on cursor 2
END LOOP;
END
Exceptionally "on delete cascade foreign keys" can be useful but I don't want people to break their "best practice" rules because of a post. After all it can definitely be a potential issue if "one delete cascade" is not carefully used, documented etc.
See this thread for example : Re: PL/SQL on delete cascade.. ( how to view the child record deleted..?)
Tom Kyte is also very cautious about that : http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3125592573416
I don't like it personally -- I'd rather have an error when I delete a parent that has child
records. Doesn't "seem" right to have that stuff just disappear.
It is useful in limited cases.
Similar Messages
-
Implementing a Constraint Satisfaction Problem?
Good afternoon,
I'm having a lot of troubles implementing a Constraint Satisfaction Problem that requires the implementation of a restriction solver of finite domains (integers) under a java language.
The system must allow:
- Create restricted variables giving the domain limits with the class name "Variable".
.Ex:
Variable X = new Variable(1,10);
Variable Y = new Variable(7,10);
- Create the restrictions on the variables. The restrictions must by defined on the class "Constraint", the following restrictions shall be defined on the corresponding subclasses.
The restrictions should always involve just two variables. The restrictions X=/Y, X=Y+C (C is a constant), X=Y, X>Y and X>=Y using the classes NEQ, NEPlus, EQ, GT and GE must be implemented.
.Ex:
Constraint c1 = new NEQ(X,Y);
Constraint c2 = new NEPlus(X,Y,2);
-One iterator named "VarIterator" which allows iterate under the variables of the iterator and obtain solutions.It must contain the methods start() and next() to initialize the iterator and obtain the solutions.
.Ex:
VarIterator it=new VarIterator(X);
it.addVariable(Y);
it.start();
PS: I'm very thankful in advance to anyone who can help with this, i'm having problems just to start this and it's a assignment that i would like very much to succeed._fwank_ wrote:
The objective of my post wasn't to someone make the "homework", but to get any kind of help that could direct me to some kind of way to at least start the work.Then logically you should have asked a specific question or two, not just dumped your homework assignment here and saying vague things like "having a lot of troubles doing this", don't you think? What you posted obviously amounts to, in summary: "Please do my homework for me!" -
Primary key columns dropped with cascade constraint
Hi,
My developer dropped one column from table which was having primary key . (primary key on two columns now one column is there)
he used SQL > alter table table_name drop columns cascade constraints.
Now i want to enable the constraint. the constraint is not there. if i am creating the primary key with the existing single column alone.
My question how do i know which was the dependency it had? (like foreign key / child tables it had?) and how to rebuild the relationship?
Thanks
--RamanHemangi,
i am just wondering before dropping the column we had primary key. (as i mentioned earlier the primary key was created for two columns ) .
now if i am re-building by just adding primary key to the existinc column alone i am facing this error.
Let me see if there is any null or duplicate values in the column.
Thanks
--Raman -
Implementing the Dunning Procedure
How to implement the dunning procedure onto the system? What are the t-codes and configurations?
Thanks in advance!Hello
Sending dunning notice means sending reminders notice to customers in reference to their outstanding balance.You can set up dunning procedure in customer master data.You cannot send dunning notice until dunning procedure is set up in customer master data.Kindly refer to below mentioned link for more information.
http://academic.uofs.edu/faculty/gramborw/sap/dunning.htm
Please be generous if u wish to assign points.
Salam Namaste -
BC4J: Implementing cascade-delete
Hi,
I'm using BC4J (JDev 9.0.3.4) and I'd like my composite associations with cascade delete to realy behave like one would usualy expect... that is, when the master entity is deleted, the details are not only deleted from the database but from the view object and entity caches as well. Is there a way to accomplish that?
I was thinking about extending EntityImpl and overiding the remove or doDML method to remove the detail entities from the vo and eo caches. Is this the correct approach? Any other options?
Thanks,
LeonardoIf you use the JDev 9.0.3.5 or later, you could
select "Implement cascade delete" option in the
Association properties for your composition
association. This flag enables the framework to
remove all details for a master when the master is
deleted.Hi, Thanks for your reply.
We're using 9.0.3.4 and unfortunately upgrading is not an option for us at this time. What would be the correct way to implement it using 9.0.3.4?
Thanks,
Leonardo Bueno -
Java System Clipboard error implementing inhereted lostOwnership procedure
I am trying to get a string from the system clipboard manipulate it then put the manipulated string back on the system clipboard. I'm fairly certain i have the accessing the clipboard correct, but i can't figure out an error i'm getting with part of it.
Error Message:
Syntax error on token "}", delete this token
It refers to the "}" that closes the scope of the lostOwnership procedure, which has to be implemented by the class because it is inherited from the "implements ClipboardOwner", but is not implemented by it.
Code:
public class Programming12 implements ClipboardOwner{
private static JFrame frame = new JFrame("HTS Programming 12");
private static JTextArea ta;
private static JButton start = new JButton("START");
private ClipboardOwner co = this;//must do this because need to use "this" as the ClipboardOwner inside a static
//function
public void lostOwnership(Clipboard clipboard, Transferable contents){}/*procedure*/Any help would be appreciated, even if you can possibly point me in the right direction.
Edited by: Bherms on Dec 13, 2009 10:41 PMIt works just fine for me (no syntax errors):
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import javax.swing.*;
public class ClipBoardTest implements ClipboardOwner
private static JFrame frame = new JFrame("HTS Programming 12");
private static JTextArea ta;
private static JButton start = new JButton("START");
private ClipboardOwner co = this;//must do this because need to use "this" as the ClipboardOwner inside a static
//function
public void lostOwnership(Clipboard clipboard, Transferable contents){}/*procedure*/
} -
JPA - How can i add ON DELETE CASCADE constraint ?
I have a three tables.
1. A (name)
2. B (name)
and relationship(manytomany) table of A and B
3. C (a_name,b_name)
I am using 2 JPA entities@Entity
public class A {
@id
String name;
@ManyToMany
@JoinTable(name="C",
joinColumns=@JoinColumn(name="a_name"),
inverseJoinColumns=@JoinColumn(name="b_name"))
private List<B> bs = new ArrayList<B>();
//getter setter methos
}and@Entity
public class B {
@id
String name;
@ManyToMany(mappedBy="bs")
private List<A> as = new ArrayList<A>();
//getter setter methos
}DDL of table C which is generated by JPA is something like thatCREATE TABLE C (
"a_name" VARCHAR,
"b_name" VARCHAR,
CONSTRAINT "c_a_name_fkey" FOREIGN KEY ("a_name")
REFERENCES a(name)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT "c_b_name_fkey" FOREIGN KEY ("b_name")
REFERENCES b(name)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)but i want to add constraint ON DELETE CASCADE* instead of ON DELETE NO ACTION_ in above relationship table C.
how can i do this ?
Thanks in advance.Right click the message and select Edit as New.
-
APEX DB: Not accepting the constraint ON UPDATE CASCADE
Hi
My schema tables is not accepting the ON UPDATE CASCADE constraint as it was accepting the ON DELETE CASCADE constraint. My use case is to update the records in the child tables, when a PK of parent table is modified/updated. Please help.
Thanks
BhaveshBavesh,
Boy this question could spark a huge debate about relational theory and the merits of allowing the update of a primary key... But instead of stirring the pot, I'll answer your question. :-)
Unfortunately Oracle does not support the ON UPDATE CASCADE constraint that PostgreSQL and other databases do.
You might look at [this discussion|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5773459616034] on ASK TOM where he talks about the merits and references a couple ways you can achieve similar things in Oracle.
Hope That Helps,
- Doug -
http://sumnertech.com/ -
Using commit and delete in cascade implementation.
Good morning.
I want to do the next task:
I have two entities, province and city, which includes an association between them, which implements cascade delete.
I want to delete a province, and after that, do the commit operation en the same operation.
The province and cities are erased correctly in memory, but during the commit operation, it shows an integrity exception, showings that there are secundary registries in DDBB.
Any solution?
Thanks in advance,
Jaime.Exactly Frank.
The secuence is thw following:
We have the next tables:
Province City
Id province Des province Id City Des City Id Province
1 A 1 AA 1
2 BB 1
When I Delete the Province '1', in memory it also deletes the citys '1' and '2'.
The problem is when the commit operation, because the DDBB detects that there is secundary registries asocciates to province '1'.
I want to delete the Province '1', and also, the citys '1' and '2' in DDBB also.
Thanks in advance,
Jaime. -
REPEATED POST: Using commit and delete in cascade implementation.
Good morning.
I want to do the next task:
I have two entities, province and city, which includes an association between them, which implements cascade delete.
I want to delete a province, and after that, do the commit operation en the same operation.
The province and cities are erased correctly in memory, but during the commit operation, it shows an integrity exception, showings that there are secundary registries in DDBB.
Any solution?
Thanks in advance,
Jaime.Exactly Frank.
The secuence is thw following:
We have the next tables:
Province City
Id province Des province Id City Des City Id Province
1 A 1 AA 1
2 BB 1
When I Delete the Province '1', in memory it also deletes the citys '1' and '2'.
The problem is when the commit operation, because the DDBB detects that there is secundary registries asocciates to province '1'.
I want to delete the Province '1', and also, the citys '1' and '2' in DDBB also.
Thanks in advance,
Jaime. -
Cascading Parameters prompting twice when scheduling report on CMC
Hi all,
I am having some difficulty with the Central Management Console (CMC) when scheduling a report I created.
The report contains one sub-report with a stored procedure to generate the data. This stored procedure has 5 parameters including region and city. In the main report I implemented cascading parameters for region and city and passed their values to the parameters of the stored procedure for the sub-report. All of this works fine within Crystal Reports when I run the report and even when I use the "View" option in CMC. However when I use the "Schedule" option in CMC to schedule the report and I am setting the parameters for the report, there is some odd behavior. The first parameter shows two values, one for region and one for city (this is fine). The next parameter is a string variable. When I try to set this parameter, I am prompted again with the cascading parameters for the region and city. This messes up all the parameters and if I continue to set the other parameters, I am prompted to give a value for the previous parameter.
Why am I being prompted twice to enter a value for the cascading parameters? How can I fix this?
Thanks in advance for your help.
P.S. I thought about using the cascading parameters as filters in the Crystal Report itself but this causes the report to be slow as a lot of data is brought back from the stored procedure before filtering.
P.P.S. I am using Crystal Reports 2008Hi Jevon,
What version of BO (Service Pack, Patch) are you using?
Try upgrading the version to a higher Service Pack/Patch on a Test environment to see if that resolves the issue.
-Abhilash -
Calling a procedure from within a procedure
Hi Guys,
I have created a package to base a form on. The package contains some procedures, one of which is an Update procedure which can be seen below. I have a procedure in another package that I am trying to call. Basically the second procedure is called to implement a constraint. However, I am unsure as to what I should pass into this procedure, as a package/procedure for basing a form on is different to what I have come across before.
CREATE OR REPLACE package staff_dml IS
TYPE staff_rec IS RECORD (staff_id NUMBER(7),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
tel_no NUMBER(11),
manager_id NUMBER(7),
position VARCHAR2(20),
rest_id NUMBER(7),
grade VARCHAR2(1),
wage NUMBER(7,2));
TYPE staff_cursor IS REF CURSOR RETURN staff_rec;
TYPE staff_table IS TABLE OF staff_rec INDEX BY BINARY_INTEGER;
PROCEDURE staff_update (data IN OUT staff_table);
PROCEDURE staff_find (data IN OUT staff_cursor);
PROCEDURE staff_lock (data IN OUT staff_table);
END;
CREATE OR REPLACE PACKAGE BODY staff_dml IS
PROCEDURE staff_lock (data IN OUT staff_table)
IS
temp NUMBER;
BEGIN
SELECT staff_id into temp
FROM staff
WHERE staff_id = data(1).staff_id
FOR UPDATE;
END staff_lock;
PROCEDURE staff_find (data IN OUT staff_cursor)
IS
BEGIN
OPEN data FOR SELECT staff_id, first_name, last_name, tel_no, manager_id, position, rest_id, grade, wage
FROM staff;
END staff_find;
PROCEDURE staff_update
(data IN OUT staff_table)
IS
BEGIN
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
UPDATE staff
SET first_name = data(1).first_name, last_name = data(1).last_name, tel_no = data(1).tel_no, manager_id = data(1).manager_id,
position = data(1).position, rest_id = data(1).rest_id, grade = data(1).grade, wage = data(1).wage
WHERE staff_id = data(1).staff_id;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE||' '||SQLERRM);
END staff_update;
END;
The area I an concerned about is:
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
I do not know what I should be passing into the special_pkg.staff_chk procedure which accepts two number inputs. I want to use this package to compare the new inputs on this to the existing ones (this is carried out by the procedure. I have tried using :new. but this is not accepted. If I leave in the EXCEPTION then i get no errors from the form, but it will not save any changes I make on the database. If I remove the EXCEPTION then I get an error from the form - FRM-40735 UPDATE-PROCEDURE trigger raised unhandled exception ORA-04098. I am pretty sure this is because I am not supplying the correct variables to the called procedure,
The called procedure is below (tested and working):
PROCEDURE staff_chk
(p_wage IN NUMBER,
p_grade IN NUMBER)
IS
BEGIN
IF p_wage BETWEEN 0 AND 7.00 AND p_grade != 'C' THEN
RAISE_APPLICATION_ERROR(-20002, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 7.01 AND 10 AND p_grade != 'B' THEN
RAISE_APPLICATION_ERROR(-20003, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 10.01 AND 20 AND p_grade != 'A' THEN
RAISE_APPLICATION_ERROR(-20004, 'The Incorrect grade has been applied to this employee');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Staff member does not exist');
END staff_chk;
END;
Any help would be greatly appreciated.
Thanks,
AntonSince this appears to be an Oracle Forms related question, you may want to pose it over in the Oracle Forms forum.
Forms
The folks over there are a lot more likely to be able to solve your problem.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Calling a procedure from within a procedure - dif to post below
Hi Guys,
I have created a package to base a form on. The package contains some procedures, one of which is an Update procedure which can be seen below. I have a procedure in another package that I am trying to call. Basically the second procedure is called to implement a constraint. However, I am unsure as to what I should pass into this procedure, as a package/procedure for basing a form on is different to what I have come across before.
CREATE OR REPLACE package staff_dml IS
TYPE staff_rec IS RECORD (staff_id NUMBER(7),
first_name VARCHAR2(20),
last_name VARCHAR2(20),
tel_no NUMBER(11),
manager_id NUMBER(7),
position VARCHAR2(20),
rest_id NUMBER(7),
grade VARCHAR2(1),
wage NUMBER(7,2));
TYPE staff_cursor IS REF CURSOR RETURN staff_rec;
TYPE staff_table IS TABLE OF staff_rec INDEX BY BINARY_INTEGER;
PROCEDURE staff_update (data IN OUT staff_table);
PROCEDURE staff_find (data IN OUT staff_cursor);
PROCEDURE staff_lock (data IN OUT staff_table);
END;
CREATE OR REPLACE PACKAGE BODY staff_dml IS
PROCEDURE staff_lock (data IN OUT staff_table)
IS
temp NUMBER;
BEGIN
SELECT staff_id into temp
FROM staff
WHERE staff_id = data(1).staff_id
FOR UPDATE;
END staff_lock;
PROCEDURE staff_find (data IN OUT staff_cursor)
IS
BEGIN
OPEN data FOR SELECT staff_id, first_name, last_name, tel_no, manager_id, position, rest_id, grade, wage
FROM staff;
END staff_find;
PROCEDURE staff_update
(data IN OUT staff_table)
IS
BEGIN
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
UPDATE staff
SET first_name = data(1).first_name, last_name = data(1).last_name, tel_no = data(1).tel_no, manager_id = data(1).manager_id,
position = data(1).position, rest_id = data(1).rest_id, grade = data(1).grade, wage = data(1).wage
WHERE staff_id = data(1).staff_id;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE||' '||SQLERRM);
END staff_update;
END;
The area I an concerned about is:
IF data(1).wage != data(1).wage THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
IF data(1).grade != data(1).grade THEN
special_pkg.staff_chk(data(1).wage,data(1).grade);
END IF;
I do not know what I should be passing into the special_pkg.staff_chk procedure which accepts two number inputs. I want to use this package to compare the new inputs on this to the existing ones (this is carried out by the called procedure). I have tried using :new. but this is not accepted. If I leave in the EXCEPTION then i get no errors from the form, but it will not save any changes I make on the database. If I remove the EXCEPTION then I get an error from the form - FRM-40735 UPDATE-PROCEDURE trigger raised unhandled exception ORA-04098. I am pretty sure this is because I am not supplying the correct variables to the called procedure,
The called procedure is below (tested and working):
PROCEDURE staff_chk
(p_wage IN NUMBER,
p_grade IN NUMBER)
IS
BEGIN
IF p_wage BETWEEN 0 AND 7.00 AND p_grade != 'C' THEN
RAISE_APPLICATION_ERROR(-20002, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 7.01 AND 10 AND p_grade != 'B' THEN
RAISE_APPLICATION_ERROR(-20003, 'The Incorrect grade has been applied to this employee');
ELSIF p_wage BETWEEN 10.01 AND 20 AND p_grade != 'A' THEN
RAISE_APPLICATION_ERROR(-20004, 'The Incorrect grade has been applied to this employee');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Staff member does not exist');
END staff_chk;
END;
Any help would be greatly appreciated.
Thanks,
AntonHi,
You triggered in fired on table and you procedure in acting is on the same table which rasing the exception.
Go throw this link you will understand
http://asktom.oracle.com/tkyte/Mutate/
- Pavan Kumar N -
How to implement a 1-n relationship
I'm using oracle 8.1 and currently learning JDO.
Havin the following schema :
DROP TABLE permission_group_map CASCADE CONSTRAINTS;
CREATE TABLE permission_group_map (
permission_group_map_oid NUMBER(10) NOT NULL,
version_oid NUMBER(3) NOT NULL,
group_oid NUMBER(10) NOT NULL,
permission_oid NUMBER(10) NOT NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL
ALTER TABLE permission_group_map
ADD ( CONSTRAINT PKpermission_group_map PRIMARY KEY (
permission_group_map_oid) ) ;
DROP TABLE permission CASCADE CONSTRAINTS;
CREATE TABLE permission (
permission_oid NUMBER(10) NOT NULL,
version_oid NUMBER(3) NOT NULL,
name VARCHAR2(60) NULL,
visibility NUMBER(1) NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL
ALTER TABLE permission
ADD ( CONSTRAINT PKpermission PRIMARY KEY (permission_oid,
version_oid) ) ;
DROP TABLE user_group CASCADE CONSTRAINTS;
CREATE TABLE user_group (
group_oid NUMBER(10) NOT NULL,
name VARCHAR2(60) NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL
ALTER TABLE user_group
ADD ( CONSTRAINT PKuser_group PRIMARY KEY (group_oid) ) ;
ALTER TABLE permission_group_map
ADD ( CONSTRAINT fk2_permission_group_map
FOREIGN KEY (group_oid)
REFERENCES user_group ) ;
ALTER TABLE permission_group_map
ADD ( CONSTRAINT fk1_permission_group_map
FOREIGN KEY (permission_oid, version_oid)
REFERENCES permission ) ;
How can represent a 1-n relation in a .jdo file without adding more fileds.
Here is my .jdo implementation
<class identity-type="application" name="UserGroup"
objectid-class="UserGroupKey" requires-extent="false">
<extension key="table" value="USER_GROUP" vendor-name="kodo"/>
<field name="name" null-value="exception" primary-key="false">
<extension key="data-column" value="NAME"
vendor-name="kodo"/>
<extension key="column-length" value="60"
vendor-name="kodo"/>
</field>
<field name="userId" null-value="exception"
primary-key="false">
<extension key="data-column" value="USER_ID"
vendor-name="kodo"/>
</field>
<field name="groupOid" null-value="exception"
primary-key="true">
<extension key="data-column" value="GROUP_OID"
vendor-name="kodo"/>
</field>
<field name="timestamp" null-value="exception"
primary-key="false">
<extension key="data-column" value="TIMESTAMP"
vendor-name="kodo"/>
</field>
<field name = "permissionGroupMap">
<collection element-type="PermissionGroupMap"/>
<extension vendor-name="kodo" key="inverse"
value="userGroup"/>
</field>
<extension key="lock-column" value="jdolock"
vendor-name="kodo"/>
<extension key="class-column" value="none" vendor-name="kodo"/>
</class>
<class identity-type="application" name="PermissionGroupMap"
objectid-class="PermissionGroupMapKey" requires-extent="false">
<extension key="table" value="PERMISSION_GROUP_MAP"
vendor-name="kodo"/>
<extension key="lock-column" value="jdolock"
vendor-name="kodo"/>
<extension key="class-column" value="none" vendor-name="kodo"/>
<field name="permissionGroupMapOid" null-value="exception"
primary-key="true">
<extension key="data-column"
value="PERMISSION_GROUP_MAP_OID" vendor-name="kodo"/>
</field>
<field name="userId" null-value="exception"
primary-key="false">
<extension key="data-column" value="USER_ID"
vendor-name="kodo"/>
</field>
<field name="permissionOid" null-value="exception"
primary-key="false">
<extension key="data-column" value="PERMISSION_OID"
vendor-name="kodo"/>
</field>
<field name="groupOid" null-value="exception"
primary-key="false">
<extension key="data-column" value="GROUP_OID"
vendor-name="kodo"/>
</field>
<field name="versionOid" null-value="exception"
primary-key="false">
<extension key="data-column" value="VERSION_OID"
vendor-name="kodo"/>
</field>
<field name="timestamp" null-value="exception"
primary-key="false">
<extension key="data-column" value="TIMESTAMP"
vendor-name="kodo"/>
</field>
</class>
and here is the class code
public class PermissionGroupMap {
java.math.BigDecimal permissionGroupMapOid;
java.lang.String userId;
java.math.BigDecimal permissionOid;
java.math.BigDecimal groupOid;
java.math.BigDecimal versionOid;
java.util.Date timestamp;
/** relationship fields **/
UserGroup userGroup;
public class UserGroup {
java.lang.String name;
java.lang.String userId;
java.math.BigDecimal groupOid;
java.util.Date timestamp;
/** relationship fields **/
ArrayList permissionGroupMap = new ArrayList();
Here is the exception that I'm getting :
javax.jdo.JDODataStoreException: [SQL=SELECT t0.PERMISSION_GROUP_MAP_OID,
t0.jdolock, t0.GROUP_OID, t0.PERMISSION_OID, t0.TIMESTAMP,
t0.GROUPOID_USERGROUPX, t0.USER_ID, t0.VERSION_OID FROM
PERMISSION_GROUP_MAP t0 WHERE t0.GROUPOID_USERGROUPX = 1] ORA-00904:
invalid column nameThanks for you quick response, But I changed the schema a little bit, just
to play arround, now I'm doing a m-n, but it does not work, can you tell
me what I'm doing wrong, here is the schema :
CREATE TABLE user_group (
group_oid NUMBER(10) NOT NULL,
name VARCHAR2(60) NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL,
CONSTRAINT PKuser_group
PRIMARY KEY (group_oid)
CREATE TABLE permission (
permission_oid NUMBER(10) NOT NULL,
version_oid NUMBER(3) NOT NULL,
name VARCHAR2(60) NULL,
visibility NUMBER(1) NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL,
CONSTRAINT PKpermission
PRIMARY KEY (permission_oid, version_oid)
CREATE TABLE permission_group_map (
group_oid NUMBER(10) NOT NULL,
permission_oid NUMBER(10) NOT NULL,
version_oid NUMBER(3) NOT NULL,
CONSTRAINT PKpermission_group_map
PRIMARY KEY (group_oid, permission_oid, version_oid),
CONSTRAINT R_4
FOREIGN KEY (permission_oid, version_oid)
REFERENCES permission,
CONSTRAINT R_3
FOREIGN KEY (group_oid)
REFERENCES user_group
the .jod file :
<class identity-type="application" name="Permission"
objectid-class="PermissionKey" requires-extent="false">
<extension key="table" value="PERMISSION" vendor-name="kodo"/>
<field name="permissionOid" null-value="exception"
persistence-modifier="persistent" primary-key="true">
<extension key="data-column" value="PERMISSION_OID"
vendor-name="kodo"/>
<extension key="column-length" value="10"
vendor-name="kodo"/>
<extension key="column-index" value="pkPermission"
vendor-name="kodo"/>
</field>
<field name="versionOid" null-value="exception"
persistence-modifier="persistent" primary-key="true">
<extension key="data-column" value="VERSION_OID"
vendor-name="kodo"/>
<extension key="column-index" value="pkPermission"
vendor-name="kodo"/>
<extension key="column-length" value="3"
vendor-name="kodo"/>
</field>
<field name="userGroups">
<collection element-type="UserGroup"/>
<extension vendor-name="kodo" value="permissions"/>
<extension vendor-name="kodo" key="table"
value="PERMISSION_GROUP_MAP"/>
<extension vendor-name="kodo" key="groupOid-data-column"
value="GROUP_OID"/>
<extension vendor-name="kodo"
key="permissionOid-ref-column" value="PERMISSION_OID"/>
<extension vendor-name="kodo" key="versionOid-ref-column"
value="VERSION_OID"/>
</field>
<extension key="class-column" value="none" vendor-name="kodo"/>
<extension key="lock-column" value="jdolock"
vendor-name="kodo"/>
</class>
<class identity-type="application" name="UserGroup"
objectid-class="UserGroupKey" requires-extent="false">
<extension key="table" value="USER_GROUP" vendor-name="kodo"/>
<field name="name" null-value="exception" primary-key="false">
<extension key="data-column" value="NAME"
vendor-name="kodo"/>
<extension key="column-length" value="60"
vendor-name="kodo"/>
</field>
<field name="permissions">
<extension vendor-name="kodo" value="userGroups"/>
<extension vendor-name="kodo" key="table"
value="PERMISSION_GROUP_MAP"/>
<extension vendor-name="kodo" key="groupOid-ref-column"
value="GROUP_OID"/>
<extension vendor-name="kodo"
key="permissionOid-data-column" value="PERMISSION_OID"/>
<extension vendor-name="kodo" key="versionOid-data-column"
value="VERSION_OID"/>
</field>
<extension key="lock-column" value="jdolock"
vendor-name="kodo"/>
<extension key="class-column" value="none" vendor-name="kodo"/>
</class>
CODE :
public class Permission {
java.math.BigDecimal visibility;
java.lang.String name;
java.lang.String userId;
java.math.BigDecimal permissionOid;
java.math.BigDecimal versionOid;
java.util.Date timestamp;
private Collection userGroups = new ArrayList();
public class UserGroup {
java.lang.String name;
java.lang.String userId;
java.math.BigDecimal groupOid;
java.util.Date timestamp;
Collection permissions = new ArrayList();
Patrick Linskey wrote:
Manuel,
When mapping relations to pre-defined schemas using application identity,
you must use the '<fieldname>-data-column' extension syntax discussed in
http://www.solarmetric.com/Software/Documentation/2.2.6/manual.html#metadata
_extensions.
Additionally, in general, you should not have foreign key fields declared in
your java code as well as relations to other objects. For example, in
PermissionGroupMap, you should just have a relation to UserGroup, and no
groupOid field -- the foreign key information will be handled by JDO, and
should not be user-accessible except through the UserGroup relation.
So, something like this is probably more like what you want (I've removed
some fields for brevity):
<class identity-type="application" name="UserGroup"
objectid-class="UserGroupKey" requires-extent="false">
<field name="groupOid" null-value="exception" primary-key="true">
<extension key="data-column" value="GROUP_OID"
vendor-name="kodo"/>
</field>
<field name = "permissionGroupMap">
<collection element-type="PermissionGroupMap"/>
<extension vendor-name="kodo" key="inverse" value="userGroup"/>
</field>
</class>
<class identity-type="application" name="PermissionGroupMap"
objectid-class="PermissionGroupMapKey" requires-extent="false">
<field name="permissionGroupMapOid" null-value="exception"
primary-key="true">
<extension key="data-column" value="PERMISSION_GROUP_MAP_OID"
vendor-name="kodo"/>
</field>
<field name="userGroup" null-value="exception" primary-key="false">
<extension key="groupOid-data-column" value="GROUP_OID"
vendor-name="kodo"/>
</field>
</class>
public class PermissionGroupMap {
java.math.BigDecimal permissionGroupMapOid;
// this is not needed: java.math.BigDecimal groupOid;
/** relationship fields **/
UserGroup userGroup;
public class UserGroup {
java.math.BigDecimal groupOid;
/** relationship fields **/
ArrayList permissionGroupMap = new ArrayList();
On 6/8/02 11:56 AM, "Manuel Ledesma" <[email protected]> wrote:
I'm using oracle 8.1 and currently learning JDO.
Havin the following schema :
DROP TABLE permission_group_map CASCADE CONSTRAINTS;
CREATE TABLE permission_group_map (
permission_group_map_oid NUMBER(10) NOT NULL,
version_oid NUMBER(3) NOT NULL,
group_oid NUMBER(10) NOT NULL,
permission_oid NUMBER(10) NOT NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL
ALTER TABLE permission_group_map
ADD ( CONSTRAINT PKpermission_group_map PRIMARY KEY (
permission_group_map_oid) ) ;
DROP TABLE permission CASCADE CONSTRAINTS;
CREATE TABLE permission (
permission_oid NUMBER(10) NOT NULL,
version_oid NUMBER(3) NOT NULL,
name VARCHAR2(60) NULL,
visibility NUMBER(1) NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL
ALTER TABLE permission
ADD ( CONSTRAINT PKpermission PRIMARY KEY (permission_oid,
version_oid) ) ;
DROP TABLE user_group CASCADE CONSTRAINTS;
CREATE TABLE user_group (
group_oid NUMBER(10) NOT NULL,
name VARCHAR2(60) NULL,
jdolock NUMBER NULL,
user_id VARCHAR2(20) NULL,
timestamp DATE NULL
ALTER TABLE user_group
ADD ( CONSTRAINT PKuser_group PRIMARY KEY (group_oid) ) ;
ALTER TABLE permission_group_map
ADD ( CONSTRAINT fk2_permission_group_map
FOREIGN KEY (group_oid)
REFERENCES user_group ) ;
ALTER TABLE permission_group_map
ADD ( CONSTRAINT fk1_permission_group_map
FOREIGN KEY (permission_oid, version_oid)
REFERENCES permission ) ;
How can represent a 1-n relation in a .jdo file without adding more fileds.
Here is my .jdo implementation
<class identity-type="application" name="UserGroup"
objectid-class="UserGroupKey" requires-extent="false">
<extension key="table" value="USER_GROUP" vendor-name="kodo"/>
<field name="name" null-value="exception" primary-key="false">
<extension key="data-column" value="NAME"
vendor-name="kodo"/>
<extension key="column-length" value="60"
vendor-name="kodo"/>
</field>
<field name="userId" null-value="exception"
primary-key="false">
<extension key="data-column" value="USER_ID"
vendor-name="kodo"/>
</field>
<field name="groupOid" null-value="exception"
primary-key="true">
<extension key="data-column" value="GROUP_OID"
vendor-name="kodo"/>
</field>
<field name="timestamp" null-value="exception"
primary-key="false">
<extension key="data-column" value="TIMESTAMP"
vendor-name="kodo"/>
</field>
<field name = "permissionGroupMap">
<collection element-type="PermissionGroupMap"/>
<extension vendor-name="kodo" key="inverse"
value="userGroup"/>
</field>
<extension key="lock-column" value="jdolock"
vendor-name="kodo"/>
<extension key="class-column" value="none" vendor-name="kodo"/>
</class>
<class identity-type="application" name="PermissionGroupMap"
objectid-class="PermissionGroupMapKey" requires-extent="false">
<extension key="table" value="PERMISSION_GROUP_MAP"
vendor-name="kodo"/>
<extension key="lock-column" value="jdolock"
vendor-name="kodo"/>
<extension key="class-column" value="none" vendor-name="kodo"/>
<field name="permissionGroupMapOid" null-value="exception"
primary-key="true">
<extension key="data-column"
value="PERMISSION_GROUP_MAP_OID" vendor-name="kodo"/>
</field>
<field name="userId" null-value="exception"
primary-key="false">
<extension key="data-column" value="USER_ID"
vendor-name="kodo"/>
</field>
<field name="permissionOid" null-value="exception"
primary-key="false">
<extension key="data-column" value="PERMISSION_OID"
vendor-name="kodo"/>
</field>
<field name="groupOid" null-value="exception"
primary-key="false">
<extension key="data-column" value="GROUP_OID"
vendor-name="kodo"/>
</field>
<field name="versionOid" null-value="exception"
primary-key="false">
<extension key="data-column" value="VERSION_OID"
vendor-name="kodo"/>
</field>
<field name="timestamp" null-value="exception"
primary-key="false">
<extension key="data-column" value="TIMESTAMP"
vendor-name="kodo"/>
</field>
</class>
and here is the class code
public class PermissionGroupMap {
java.math.BigDecimal permissionGroupMapOid;
java.lang.String userId;
java.math.BigDecimal permissionOid;
java.math.BigDecimal groupOid;
java.math.BigDecimal versionOid;
java.util.Date timestamp;
/** relationship fields **/
UserGroup userGroup;
public class UserGroup {
java.lang.String name;
java.lang.String userId;
java.math.BigDecimal groupOid;
java.util.Date timestamp;
/** relationship fields **/
ArrayList permissionGroupMap = new ArrayList();
Here is the exception that I'm getting :
javax.jdo.JDODataStoreException: [SQL=SELECT t0.PERMISSION_GROUP_MAP_OID,
t0.jdolock, t0.GROUP_OID, t0.PERMISSION_OID, t0.TIMESTAMP,
t0.GROUPOID_USERGROUPX, t0.USER_ID, t0.VERSION_OID FROM
PERMISSION_GROUP_MAP t0 WHERE t0.GROUPOID_USERGROUPX = 1] ORA-00904:
invalid column name
Patrick Linskey [email protected]
SolarMetric Inc. http://www.solarmetric.com -
Warning: Procedure created with compilation errors.
I am trying to upload a pdf file into a blob column of a table. I get this error with these three ways of doing that:Warning: Procedure created with compilation errors.
Any ideas why?
-- THE STORAGE TABLE FOR THE IMAGE FILE
ALTER TABLE PDM
DROP PRIMARY KEY CASCADE;
DROP TABLE PDM CASCADE CONSTRAINTS;
CREATE TABLE PDM (
DNAME VARCHAR2(30), -- DIRECTORY NAME
SNAME VARCHAR2(30), -- SUBDIRECTORY NAME
FNAME VARCHAR2(30), -- FILE NAME
IBLOB BLOB); -- IMAGE FILE
-- CREATE THE PROCEDURE TO LOAD THE FILE
CREATE OR REPLACE PROCEDURE LOAD_FILE (
PDNAME VARCHAR2,
PSNAME VARCHAR2,
PFNAME VARCHAR2) IS
SRC_FILE BFILE;
DST_FILE BLOB;
LGH_FILE BINARY_INTEGER;
BEGIN
SRC_FILE := BFILENAME('PDF_DIR', '266-5210.pdf');
-- INSERT A NULL RECORD TO LOCK
INSERT INTO PDM
(DNAME, SNAME, FNAME, IBLOB)
VALUES
(PDNAME, PSNAME, PFNAME, EMPTY_BLOB())
RETURNING IBLOB INTO DST_FILE;
-- LOCK RECORD
SELECT IBLOB
INTO DST_FILE
FROM PDM
WHERE DNAME = PDNAME
AND SNAME = PSNAME
AND FNAME = PFNAME
FOR UPDATE;
-- OPEN THE FILE
DBMS_LOB.FILEOPEN(SRC_FILE, DBMS_LOB.FILE_READONLY);
DBMS_LOB.OPEN(DST_FILE, DBMS_LOB.LOB_READWRITE);
-- DETERMINE LENGTH
LGH_FILE := DBMS_LOB.GETLENGTH(SRC_FILE);
-- READ THE FILE
DBMS_LOB.LOADFROMFILE(DST_FILE, SRC_FILE, LGH_FILE);
-- UPDATE THE BLOB FIELD
UPDATE PDM
SET IBLOB = DST_FILE
WHERE DNAME = PDNAME
AND SNAME = PSNAME
AND FNAME = PFNAME;
-- CLOSE FILE
DBMS_LOB.FILECLOSE(SRC_FILE);
END LOAD_FILE;
-- THE STORAGE TABLE FOR THE IMAGE FILE
ALTER TABLE PDM
DROP PRIMARY KEY CASCADE;
DROP TABLE PDM CASCADE CONSTRAINTS;
CREATE TABLE PDM
FNAME VARCHAR2(1000)
,IBLOB BLOB
-- CREATE THE PROCEDURE TO LOAD THE FILE
CREATE OR REPLACE PROCEDURE LOAD_FILE AS (
SRC_FILE BFILE := BFILENAME('PDF_DIR', '262-2827.pdf');
DST_FILE BLOB;
BEGIN
-- INSERT A NULL RECORD TO LOCK
INSERT INTO PDM
(FNAME, IBLOB)
VALUES
('262-2827.pdf', EMPTY_BLOB())
RETURNING IBLOB INTO DST_FILE;
-- OPEN THE FILE
DBMS_LOB.FILEOPEN(SRC_FILE, DBMS_LOB.FILE_READONLY);
DBMS_LOB.OPEN(DST_FILE, DBMS_LOB.LOB_READWRITE);
-- READ THE FILE
DBMS_LOB.LOADFROMFILE( SRC_FILE, DST_FILE);
-- UPDATE THE BLOB FIELD
UPDATE PDM
SET FNAME = SRC_FILE,
IBLOB = DST_FILE;
-- CLOSE FILE
DBMS_LOB.CLOSE(DST_FILE);
DBMS_LOB.FILECLOSE(SRC_FILE);
COMMIT;
END LOAD_FILE;
ALTER TABLE IMAGE_TABLE
DROP PRIMARY KEY CASCADE;
DROP TABLE IMAGE_TABLE CASCADE CONSTRAINTS;
CREATE TABLE IMAGE_TABLE (
ID NUMBER PRIMARY KEY,
IMAGE ORDSYS.ORDIMAGE);
CREATE OR REPLACE DIRECTORY IMAGEDIR AS 'C:\cards\';
GRANT READ ON DIRECTORY IMAGEDIR TO PUBLIC;
GRANT READ ON DIRECTORY MY_FILES TO twilliam;
GRANT READ ON DIRECTORY MY_FILES TO tmwillia;
CREATE OR REPLACE PROCEDURE IMAGE_IMPORT(DEST_ID NUMBER,
FILENAME VARCHAR2)
IS
IMG ORDSYS.ORDIMAGE;
CTX RAW(64) := NULL;
BEGIN
DELETE FROM IMAGE_TABLE
WHERE ID = DEST_ID;
INSERT INTO IMAGE_TABLE (ID, IMAGE)
VALUES (DEST_ID, ORDSYS.ORDIMAGE.INIT())
RETURNING IMAGE INTO IMG;
IMG.IMPORTFROM(CTX, 'FILE', 'IMAGEDIR', FILENAME);
UPDATE IMAGE_TABLE SET IMAGE=IMG WHERE ID=DEST_ID;
END
CALL IMAGE_IMPORT(7142,'125-0502.pdf');
CALL IMAGE_IMPORT(7143,'125-0503.pdf');
SELECT ID,
T.IMAGE.GETHEIGHT(),
T.IMAGE.GETWIDTH()
FROM IMAGE_TABLE T;
SELECT ID,
T.IMAGE.GETFILEFORMAT(),
T.IMAGE.GETCOMPRESSIONFORMAT()
FROM IMAGE_TABLE T;
SELECT ID,
T.IMAGE.GETCONTENTFORMAT(),
T.IMAGE.GETCONTENTLENGTH()
FROM IMAGE_TABLE T;In the second load_file procedure you should probably change the update command
-- UPDATE THE BLOB FIELD
UPDATE PDM
SET FNAME = SRC_FILE,
IBLOB = DST_FILE;into this
-- UPDATE THE BLOB FIELD
UPDATE PDM
SET IBLOB = DST_FILE
WHERE FNAME = '262-2827.pdf';but I'm not sure how to explain the eof error message. Usually this happens when you forget an "END;" or "END LOOP;" command.
Ok I rechecked and the declaration of the second procedure seems wrong
-- CREATE THE PROCEDURE TO LOAD THE FILE
CREATE OR REPLACE PROCEDURE LOAD_FILE AS (
SRC_FILE BFILE := BFILENAME('PDF_DIR', '262-2827.pdf');
DST_FILE BLOB;
BEGINshould be rewritten as
-- CREATE THE PROCEDURE TO LOAD THE FILE
CREATE OR REPLACE PROCEDURE LOAD_FILE
AS
SRC_FILE BFILE := BFILENAME('PDF_DIR', '262-2827.pdf');
DST_FILE BLOB;
BEGIN
...I removed one parenthesis which was not closed.
And for the image_import procedure there is a semikolon missing after the final END.
END*;*
Edited by: Sven W. on Nov 24, 2008 5:54 PM.
Edited by: Sven W. on Nov 24, 2008 5:56 PM
Edited by: Sven W. on Nov 24, 2008 5:59 PM
Maybe you are looking for
-
How to get the value from a servlet?
Hello guys: how can i get the value from a servlet on my jsp page,for example return a boolean variable from a servlet which API to use? thanks
-
I'm looping an array of records (from a fixed length feed) and creating a structure for each required field. Then for every loop, I'm passing this structure to a function to check if certain required field in the structure's element is left empty. Th
-
Hello - really simple question here, I think anyway. I have this line in my query - WHERE table2.trans_date_time BETWEEN :p_from_date -1 AND :p_to_date + 1 Notice the -1 + 1, I had to put this in there because if I wanted all the records that have a
-
Sparse Bundle Images on external NTFS formatted drive
I'm currently in the process of re-arranging my own backup setup following on from my recent update to Snow Leopard. For this purpose i have the lend of a NTFS formatted external drive and used a large Sparse bundle disk image. Under 10.5.7 with the
-
Replacement 3GS - What OS?
Hi all - I just sent my phone to Apple Care due to a heated battery issue, so they are sending me a new one. My question is - What OS do you think will be loaded? I'm hoping that I can just added my SIM card, turn it on and have OS 3.1.3 loaded - wit