Вопрос

I'm trying to figure out how to implement object composition using pl/sql object types. Here is my super simple example.

CREATE OR REPLACE TYPE PERSON FORCE AUTHID DEFINER UNDER MYSCHEMA.BASE_OBJECT (
    student                 ND_COMMON_ADMIN.STUDENT
) NOT FINAL;

CREATE OR REPLACE TYPE STUDENT FORCE AUTHID DEFINER UNDER MYSCHEMA.BASE_OBJECT (
    person                  ND_COMMON_ADMIN.PERSON,
    application_checklist   ND_COMMON_ADMIN.APPLICATION_CHECKLIST
) NOT FINAL;

You can see that person (the owner object) contains the student object. You can also see that student contains a person object(otherwise, student would not have access to person's data... right?)

PL/SQL however, doesn't like that these objects reference each other and throws the following error:

Error: ORA-04055: Aborted: "PERSON" formed a non-REF mutually-dependent cycle with "STUDENT".

So, if anyone could give me advice on how I can have student be a part of person via composition, but also have student be able to tell which person object it is a part of, I would greatly appreciate it.

Thanks.

Это было полезно?

Решение

According to the documentation for ORA-04055 and the following URL's you can't have actual instances of mutually dependent objects in both object types. At least one of them must be a reference.

NOTE: I am putting the definition of PERSON first because logically STUDENT appears to be a dependent of PERSON. However, if that is not the case, the declaration order can be swapped..

Also, the object that contains an actual instance of the other object must be completely defined first.

This will compile, and if both objects have REF types to the others, it will compile, but the other way around will not.

CREATE OR REPLACE TYPE STUDENTC;

CREATE OR REPLACE TYPE PERSONC   AS OBJECT (
    student1  REF STUDENTC
) NOT FINAL;
/
CREATE OR REPLACE TYPE STUDENTC   AS OBJECT  (
    person1   PERSONC,
    application_checklist   INTEGER
) NOT FINAL;
/


References:

http://psoug.org/definition/REF.htm

http://docs.oracle.com/cd/A87860_01/doc/appdev.817/a76976/adobjmng.htm

http://docs.oracle.com/cd/E11882_01/appdev.112/e11822/adobjmng.htm#i1003083

See ORACLE Documentation for ORA-04055

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top