O-R Mapping of BC4J Inheritance

We're trying to use BC4J to model our existing database schema and we're having trouble when it comes to inheritance.
Basically, the way we represent inheritence in our database is with multiple tables. For a given inheritance relationship, we have one table with all the attributes of the base class and one table with the "extra" attributes of the subclass. There is a 1 to 0/1 relatipnship between the base table and the sub table.
From what I've read, BC4J doesn't support this mapping out-of-the-box, correct? Instead, Oracle advocates replicating the base class attributes in each subclass table. We don't want to do that.
I've read several threads that suggest there is a way to override the framework to support the inheritance mapping I've described, but all of them are light on specifics (e.g. "override doDML to do...something"). Has anyone developed a solution to this problem that they're willing to share? I'm new to BC4J, but it seems like this comes up often enough that a standard solution has probably been developed...?
Thanks for your time!

We advocate and include built-in support for using the inheritance mapping strategy that gives simplest queriability over the hierarchy of types stored in a table: using a single table with a discriminator column. Simply mark one of your super-entity's attributes as the discriminator (with the declarative checkbox propert in the Entity editor) and then assign a default value to the discriminator attribute so the framework knows what discriminator value will represent the current type. For derived sub-entities, override the inherited discriminator attribute by re-adding it to the entity again -- using the admittedly oddly named (New From Table...) button -- and then override the default value of the discriminator attribute in the subentity to a distinct value that represents that entity type. Then, building polymorphic view objects that query over common attributes and return the property entity subtypes in each queried row is automatic.
We also support easily the mapping strategy that has each sub-entity in its own table.
One entity mapped to multiple tables requires either hiding that fact from BC4J by creating a database view over it, or requires overriding the doDML() method in your entity impl subclass.

Similar Messages

  • Object-Relational Mapping with BC4J

    Hi Guys,
    I am having trouble creating BC4J components for the object model below. Can BC4J take an object model with many-to-many relationship between them and create tables from it?
    Here are my classes:
    class A {
    private String id;
    private Collection bObjects; //Contains a collection of B objects (0..n)
    class B {
    private String id;
    private Collection aObjects; //Contains a collection of A objects (0..n)
    I would like to feed this object model to JDeveloper and create BC4J components and DDL from it. Is it possible?

    Bc4J does not 'map' java classes to database table but the reverse. To map a java class, you'd have to create the entity objects that mirrors your java class and then create appropriate associations including the many-to-many and then forward-generate database objects from the entity objects.
    You may be able to use Bc4j modeler to define all the above graphically!

  • Sql for  inheritance mapping looks for inherited attributes in base table

    i don't know if it is my mistake but....
    with inherited attributes (that worked OK in 10.1.3DP3) we are experiencing strange behavoir in that: the sql generated to retrieve implementors of a base class from a base table with additional attributes for subclasses read from joined tables is not valid.
    in 10.1.3DP3, the sql is correctly generated such that the attributes for subclasses are selected from the appropriate joined tables
    in 10.1.3DP4, the sql is generated such that all fields are selected from the base table, regardless whether these fields are mapped to the base class (base table) or subclasses (joined tables).
    what i expect to see is that the base table (usually aliased as t0) AND the joined table for reading subclasses (usually aliased as t1) are used in the sql statement.
    instead, all fields are selected from t0.
    i have included the generated descriptor code
    thank you very much in advance of any help here
    regards
    paul
    base class descriptor: 10.1.3DP3
    public ClassDescriptor buildAbstractEnrichmentRuleDescriptor() {
         RelationalDescriptor descriptor = new RelationalDescriptor();
         descriptor.setJavaClass(com.aon.amp.beans.enrichment.AbstractEnrichmentRule.class);
         descriptor.addTableName("ENRICHMENT_RULE");
         descriptor.addPrimaryKeyFieldName("ENRICHMENT_RULE.ENRICHMENT_RULE_ID");
         // Inheritance Properties.
         descriptor.getInheritancePolicy().setClassIndicatorFieldName("ENRICHMENT_RULE.DROP_DOWN_IND");
         descriptor.getInheritancePolicy().addClassIndicator(com.aon.amp.beans.enrichment.TextEnrichmentRule.class, "N");
         descriptor.getInheritancePolicy().addClassIndicator(com.aon.amp.beans.enrichment.DropDownEnrichmentRule.class, "Y");
         descriptor.getInheritancePolicy().dontReadSubclassesOnQueries();
    base class descriptor: 10.1.3DP4
    public ClassDescriptor buildAbstractEnrichmentRuleDescriptor() {
         RelationalDescriptor descriptor = new RelationalDescriptor();
         descriptor.setJavaClass(com.aon.amp.beans.enrichment.AbstractEnrichmentRule.class);
         descriptor.addTableName("ENRICHMENT_RULE");
         descriptor.addPrimaryKeyFieldName("ENRICHMENT_RULE.ENRICHMENT_RULE_ID");
         // Inheritance Properties.
         descriptor.getInheritancePolicy().setClassIndicatorFieldName("ENRICHMENT_RULE.DROP_DOWN_IND");
         descriptor.getInheritancePolicy().setReadAllSubclassesViewName("ENRICHMENT_RULE");
         descriptor.getInheritancePolicy().addClassIndicator(com.aon.amp.beans.enrichment.TextEnrichmentRule.class, "N");
         descriptor.getInheritancePolicy().addClassIndicator(com.aon.amp.beans.enrichment.DropDownEnrichmentRule.class, "Y");
         // Descriptor Properties.
         descriptor.useNoIdentityMap();
         descriptor.setIdentityMapSize(100);
         descriptor.useRemoteNoIdentityMap();
         descriptor.setRemoteIdentityMapSize(100);
         descriptor.setIsIsolated(true);
         descriptor.setAlias("AbstractEnrichmentRule");
    sub class descriptor:
    public ClassDescriptor buildDropDownEnrichmentRuleDescriptor() {
         RelationalDescriptor descriptor = new RelationalDescriptor();
         descriptor.setJavaClass(com.aon.amp.beans.enrichment.DropDownEnrichmentRule.class);
         descriptor.addTableName("DROP_DOWN_ENRICHMENT_RULE");
         // Inheritance Properties.
         descriptor.getInheritancePolicy().setParentClass(com.aon.amp.beans.enrichment.AbstractEnrichmentRule.class);
         descriptor.getInheritancePolicy().dontReadSubclassesOnQueries();
         // Descriptor Properties.
         descriptor.setIsIsolated(true);
         descriptor.setAlias("DropDownEnrichmentRule");
         descriptor.setCacheSynchronizationType(ClassDescriptor.DO_NOT_SEND_CHANGES);
    ...and the exception/ SQL
    Problem details
    Internal Exception: java.sql.SQLException: ORA-00904: "T0"."DROP_DOWN_SQL": invalid identifier Error Code: 904 Call:SELECT t0.ENRICHMENT_RULE_ID, t0.DROP_DOWN_IND, t0.LABEL_EXPRESSION, t0.COLUMN_NUM, t0.ORDER_PRIORITY, t0.LABEL_NAME, t0.VALUE_EXPRESSION, t0.ENRICHMENT_RULE_TYPE_ID, t0.ENRICHMENT_RULE_ID, t0.DROP_DOWN_SQL FROM ENRICHMENT_RULE t0 WHERE (t0.ENRICHMENT_BASE_ID = ?) bind => [1] Query:ReadAllQuery(com.aon.amp.beans.enrichment.AbstractEnrichmentRule)

    Hello Paul,
    There is a difference in your descriptors that is causing the problem. In the DP3 descriptor, you have selected dontReadSubclassesOnQueries() option, meaning that queries to the base class will only return base class implementations.
    The DP4 descriptor instead has setReadAllSubclassesViewName("ENRICHMENT_RULE"), which is telling it that when a query is performed on the base class that TopLink should also return subclasses. It is also telling TopLink to do this in 1 query using the ENRICHMENT_RULE view table - this allows you to specify a view that joins all the inheritance tables. This option is good when you are using cursors and the like but still need to query on the base class to get the subclasses.
    Best Regards,
    Chris Delahunt

  • Error: java.util.map can not be inherited with different arguments

    Hi,
    I am getting following error while building the source code.
    C:\venus\src\com\martquest\messaging\msgio\MqMessageIOObjectCarrier.java:36: java.util.Map cannot be inherited with different arguments: <> and <java.lang.Object,java.lang.Object>
    [javac] public class MqMessageIOObjectCarrier extends Properties implements IMqMessageIOObjectCarrier
    What should I do to resolve this issue?
    Thanks
    Prachi

    Hi,
    I am getting following error while building the
    source code.whose source code? If it's yours, you'd better look at where you are defining and using Map. The error code tells you exactly what's wrong.

  • Mapping inheritance

    We're converting an existing system to JDO. Obviously, we're going to
    be mapping the domain classes to the existing schema. There's very
    little inheritance in the current data model to worry about, but there's
    one area where we want to remodel several classes to inherit from X
    rather than own an X. X has rather a lot of data members, as do the
    candidate subclasses.
    We understand that Kodo only supports the single-table approach to
    mapping inheritance structures, but that's going to make us pay quite
    the space penalty. I'm intrigued by the field-level 'table' and
    'ref-column' extensions. The docs say they're for Collection, array,
    and Map fields, but is it possible to use these extensions to map
    non-collection inherited fields to a secondary (superclass) table? I
    don't need to make the superclass itself persistent.
    Jerry Pulley
    Sr. Developer
    Commerce Technologies, Inc.
    21 Corporate Drive
    Clifton Park, NY 12065
    518.886.0700 x3876
    518.886.0701 Fax

    Sorry; this isn't possible yet.

  • Inheritance in mapping workbench

    I try to use an existing class design with TopLink: I have for each table classes for value objects (*VO) containing only the attributes from the database tables (including the foreign keys). And I have classes for composite objects (*CO) inherited from *VO, additional containing the references to other VO and CO objects.
    A simple example:
    class FirstVO           // attributes for first database table
    private long id;     // database primary key
    private long secondId;// database foreign key to second table
    class FirstCO extends FirstVO      // references from first database table
    private SecondVO second;     // object reference to second table's object
    class SecondVO           // attributes for second database table
    private long id;     // database primary key
    In TopLink mapping workbench I have done the mapping for classes *VO. That's okay.
    When I try to do the mapping for class FirstCO, I get problems:
    - TopLink mapping workbench recognizes the class hierarchy for FirstCO fine and displays it in class info.
    - But there is not way in workbench to do the mapping of the inherited attributes for class FirstCO.
    - It does not recognize that it could use the mapping from inherited class FirstVO also for FirstCO. Setting in Descriptor/...FirstClassCO.ClassDescriptor.xml the attribute Descriptor/mappings/Mapping/inherited to true will not change this (but a green arrow up is displayed with FirstCO).
    - The workbench displays an error about class FirstCO: The following primary key fields are unmapped: ID
    How can I map this field?

    Have you setup the descriptor inheritance? Right click on the Descriptor's FirstVO and FirstCO, and select "Advanced properties--inheritance". Set the Parent Decriptor for FirstCO to be FirstVO (it's on the bottom of the inheritance tab). When you do that, you should be able to map the inherited attributes with no problems. Basically, you can remap (aka override" the mappings for superclass in subclasses.
    - Don

  • Toplink XML: polymorphism/inheritance

    Hi all,
    I have an XML like this (I have replaced the real business names by A, B, C, X ,etc etc)
    [root]
    [collectionOfX]
    [A/]
    [A/]
    [B/]
    [C/]
    [C/]
    [C/]
    [collectionOfX]
    [root]
    On the Java side, A, B and C are concrete classes extending an abstract class X. I have one root class with a collection of Xs.
    I am not able to map this stuff. Toplink requires to have concrete X elements with an attribute telling that it is in fact a A [X xsi:type="A"] and not [A]
    I have seen that substitution groups were a possible way for doing this, how does it work?
    If you have any indication about how to do this stuff, it is very welcome. I have not found any example of this.

    Ok Blaise, the example you provided me is working and I was able to apply the same principle to my project which is now working also.
    I want to share the "tricks" that will make it work for anyone after me who could face the same problem again.
    1. A, B and C must be defined as elements and these elements must be used as both schema context and default root element in the descriptor info pane of the corresponding A, B and C classes. In my case, A, B and C were complexTypes in the schema and it was not working.
    2. The abstract X class was added to the project but its descriptor was de-activated (maybe not really necessary)
    3. I have Mapped the Inherited Attributes for A, B, C concrete classes. It means the X attributes are now appearing in the A, B and C list of attributes in the workbench.
    4. The mapping of all inherited attributes is repeated in the workbench for all concrete classes (a pain if there are many attributes).
    Blaise, if possible I would like to find a better support for this case in future versions of the product. Ideally, the mapping of inherited attributes should be defined only once.
    Thx.
    Robin

  • Object to xml inheritance feature in toplink

    i created a project for object to xml mapping but require "inheritance features to be included ".i tried but it gives --"missing class indicator " and other root error
    any help please

    or send me your email i will mail you the require stuff as its to much to paste here my id is ::[email protected]
    or [email protected]

  • JPA -- Inheritance with duplicate column names

    Hi,
    I have the following problem:
    I have two tables. Let's call them BASE_TABLE and CHILD_TABLE. They are mapped through Join Inheritance in Java. In other words:
    @Inheritance(strategy=InheritanceType.JOINED)Let's say, the tables look like:
    BASE_TABLE (
        ID NUMBER(18),
        TYPE VARCHAR2(1),
        CODE NUMBER(5))
    CHILD_TABLE (
        ID NUMBER(18),
        CODE NUMBER(5),
        NAME VARCHAR2(50))Here's where the problem lies: I have duplicate column names. In my example, this is the CODE column. When mapping to Java classes, I can have something like:
    @Entity
    @Table(name="BASE_TABLE")
    @Inheritance(strategy=InheritanceType.JOINED)
    @DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING)
    @DiscriminatorValue("0")
    class BaseEntity {
        @Column(name="CODE")
        private Integer code;
        public Integer getCode_Base() {
            return code;
        public setCode_Base(Integer code) {
            this.code = code;
    @Entity
    @Table(name="CHILD_TABLE")
    @DiscriminatorValue("1")
    @PrimaryKeyJoinColumn(name="ID")
    class ChildEntity extends BaseEntity {
        @Column(name="CODE")
        private Integer code;
        public Integer getCode() {
            return code;
        public setCode(Integer code) {
            this.code = code;
    }The trouble is, that TopLink only handles ONE of the CODE columns. When SELECTing, it only selects the CODE column from table BASE_TABLE. When generating DML statements, again it only uses the CODE column from table BASE_TABLE.
    I wasn't able to make it use BOTH columns.
    Please, help. The DB design cannot be changed at the moment. However, I must find a way to make TopLink Essentials use both CODE columns, not just the one from BASE_TABLE.
    Thank you in advance!
    Best regards,
    Bisser

    Hi Chris,
    I was under the impression, that since the attributes were private, they would be treated as two different attributes by TopLink Essentials.
    Java definitely treats them as two different attributes, and not as one overriding the other. I had made sure that I could set both of them with different values (via the differently named accessors) and, indeed, both values were there. I printed them both out on the console, just to make sure. They were printed out ok, the values were indeed different.
    But TopLink Essentials was ignoring one of them.
    Now that you told me that I should use different names for the attributes, I did just that. And lo and behold, it worked!!! I couldn't even imagine that it would matter to TopLink what the names were, given that they were in two different entities that were mapped to two different tables, inheritance or not.
    As I said, Java treats them as two completely different attributes, unlike TopLink Essentials. In future, I will know that even the attribute names matter. Thank you again.
    Best regards,
    Bisser

  • Integer column for type indication in inheritance structure?

    Hi,
    I'm struggling with the mapping of an inheritance tree. The classes;
    Person and SubPerson use a flat mapping schema, with an metadata-value
    indicator for the type of the class. The latter poses some problems. The
    database column that contains the type of the class is of type INTEGER
    (using
    DB2). Apparently Kodo does not support the mapping of metadata-value
    indicator to an INTEGER column in the database. Is this correct?
    Schema:
    <table>
    <column name="TYPE" type="INTEGER"/>
    </table>
    Mapping:
    <class name="Person">
    <jdbc-class-map type="base" table="PERSON"/>
    <jdbc-version-ind type="none"/>
    <jdbc-class-ind type="metadata-value" column="TYPE"/>
    <class/>
    <class name="SubPerson">
    <jdbc-class-map type="flat" table="PERSON"/>
    <jdbc-version-ind type="none"/>
    <class/>
    Metadata:
    <class name="SubPerson" persistence-capable-superclass="Person">
    <extension vendor-name="kodo" key="data-cache-timeout" value="
    -1"/>
    <extension vendor-name="kodo" key="jdbc-class-ind-value"
    value="1"/>
    </class>
    => exception when running:
    "The "class-column" attribute/extension for the class indicator on type
    "Person.<class-indicator>" names a column whose type is not compatible with
    the expected type.
    Kind Regards,
    Stijn

    You would have to put a numerical value as Person' jdbc-class-ind-value
    extension, even if its abstract.
    Stijn Van den Enden wrote:
    Hi,
    I'm struggling with the mapping of an inheritance tree. The classes;
    Person and SubPerson use a flat mapping schema, with an metadata-value
    indicator for the type of the class. The latter poses some problems. The
    database column that contains the type of the class is of type INTEGER
    (using
    DB2). Apparently Kodo does not support the mapping of metadata-value
    indicator to an INTEGER column in the database. Is this correct?
    Schema:
    <table>
    <column name="TYPE" type="INTEGER"/>
    </table>
    Mapping:
    <class name="Person">
    <jdbc-class-map type="base" table="PERSON"/>
    <jdbc-version-ind type="none"/>
    <jdbc-class-ind type="metadata-value" column="TYPE"/>
    <class/>
    <class name="SubPerson">
    <jdbc-class-map type="flat" table="PERSON"/>
    <jdbc-version-ind type="none"/>
    <class/>
    Metadata:
    <class name="SubPerson" persistence-capable-superclass="Person">
    <extension vendor-name="kodo" key="data-cache-timeout" value="
    -1"/>
    <extension vendor-name="kodo" key="jdbc-class-ind-value"
    value="1"/>
    </class>
    => exception when running:
    "The "class-column" attribute/extension for the class indicator on type
    "Person.<class-indicator>" names a column whose type is not compatible with
    the expected type.
    Kind Regards,
    Stijn
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • Iterating the Map

    Hi there
    I am using a HashMap and I put some data in the map and I then get the data from the map with get(). However, I found that the order I get the object is in reverse order of the order that I put the data in the map. I just want to know if I can get the object from the map in the same order as I put the data.
    Thanks for your help!
    From
    Edmund

    When you iterate on a HashMap (Hashtable, HashSet...), you're actually getting them in pseudorandom order; that is, in the order of the modulo of object's hashCode value.
    Neither Maps nor Sets inheritently preserve the "input" order of their elements. If you need to do that, you'll have to use a List (LinkedList, Vector, ArrayList...)

  • [BPM] Tables are not visible

    Hi,
    I have a problem regarding the database connection of my module in BPM. In local machine, the database of the application is visible and the queries are working fine. However, in the actual environment it throws exception stating the following statement:
    fuego.components.SQLException [BEA][Oracle JDBC Driver][Oracle] ORA-00942: table or view does not exist.
    What surprises me is that I only use the same username on accessing the database.
    This is really weird for me, I'm out of ideas on how to solve this one, hope someone can rescue me.
    Thanks!

    is grants available on the tables, incase if you are using other user name to connect...
    also hope that you have created a datasource and mapped in bc4j.xfg in appmodule.xml ...
    also in configurations - change connection type from local to shared.

  • VO Attribute not saving

    I have a region on my page with x number of fields on it, they are all from a single VO relating to a single EO. On saving the record is saved to the table no probs.
    I have since added another item to the region. The item is in the VO and I have mapped the BC4J attributes to the correct field etc.
    Upon saving no data from this field is populated ( i can see data on the form).
    Have I missed something?

    Trebor,
    Were you using static styled text? If yes nature was correct it does not support all BC4J properties.It is basically use to show data and not to save data.The correct approch is your case is to use message styled text.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • JDeveloper10.1.2 & ToLink problem

    After restarting JDeveloper I have lose TopLink mapping on all inherited fields. Inherited fields not appear in TopLink structure window.
    Alexey.

    This trouble happens on russian Windows XP. I repeat all steps in english Windows XP and all works fine. The steps are:
    1. Create mypackage1.Class1 whith protected field "id" (Integer).
    2. Create mypackage2.Class2 whith protected field "name" (String). Class2 extends mypackage1.Class1.
    3. Create offline table T1 with columns ID (NUBBER, PK) and NAME (VARCHAR2).
    4. Map Class1 on T1.
    5. Map Class2 on T1 using menu "Inerited fields -> Root minus one". In structure window appears field "id".
    6. Generate mapping status report. There is no errors.
    7. Close JDeveloper.
    8. Open JDeveloper.
    9. Open Class2 mapping tab. There is no field "id" in structure window. In mapping status wrote that primary key not mapped.
    I have the same error in JDeveloper 10.1.3, but in JDeveloper 9.0.5.2 all works fine (on same computer).
    Alexey.

  • Inheritence / Aggregates / Class / Bean question

    Hi all, I'm wondering if anybody has tried/succeeded in the following:
    We have a User bean and a User class which we would like to map to one DB table with an aggregate. The user must be available un-aggregated in the mapping workbench for use by other classes which do not require the bean wrapper, so we created a ToplinkUser extending from User, which we turn on aggregation for. The bean then contains a value holder interface attribute dataObject, which we map TopLinkUser [using aggregation as said above].
    Potential issues:
    1) The plain User needs a PK mapping in the DB table, which then gets inherited by ToplinkUser, so the bean ends up with 2 writable PK mappings. The bean mapping must be writable to allow for sequencing.
    2) The User has a many to many Roles mapping which gets inherited by ToplinkUser and shows up on the list of fields that must be mapped in the aggregate usage inside the bean. Is it valid to point this back to the PK?
    Thanks in advance for any thoughts, tips, ideas, or someone who already knows it isn't possible.
    - Jesse

    1 - I'm not sure I follow the issue -- If you have inheritance setup on the descriptor, the mappings should not be duplicated in the subclass. You can override the super class mapping by right-clicking on the descriptor, and setting the visability on "Map inherited attributes".
    2 - It shouldn't have to be mapped, if there is a little "up arrow" on the mapping, that means it's inherited and mapped in the superclass.
    At runtime TopLink checks a descriptor for a mapping, and if it can't find it, if there is inheritance, it goes to the "super descriptor".
    - Don

Maybe you are looking for