Skip to main content

Problem:

  • Product Name: Borland Enterprise Server Appserver Edition
  • Platform : Windows/Solaris/Linux
  • Product Component : CMP Engine
  • JDK Version : 1.4.1

I have a unidirectional many-to-many relationship between two entities:
Table1->Table2 Table3 is the cross table in this relationship.
When I try to create a new Table2 entity, I got a NullPointerException.
Why does this happen and how can I avoid it?

Resolution:

The problem occurs because the CMP engine uses the Entity beans to discover the datatypes of its underlying tables.
When there is a uni-directional many-to-many the entity (in this case the Product entity) has no knowledge of the datatypes in the cross table.
We therefore need to help out the CMP engine by adding the crosstable datatypes to the deployment descriptor. We can add the following to the ejb-borland.xml:

<table-properties>
    <table-name>TABLE3</table-name>
    <column-properties>
        <column-name>PRO_ID</column-name>
        <property>
            <prop-name>columnJavaType</prop-name>
            <prop-type>java.lang.String</prop-type>
            <prop-value>java.math.BigDecimal</prop-value>
        </property>
        <property>
            <prop-name>ignoreOnInsert</prop-name>
            <prop-type>java.lang.Boolean</prop-type>
            <prop-value>false</prop-value>
        </property>
    </column-properties>
    <column-properties>
        <column-name>PRB_ID</column-name>
        <property>
            <prop-name>columnJavaType</prop-name>
            <prop-type>java.lang.String</prop-type>
            <prop-value>java.math.BigDecimal</prop-value>
        </property>
        <property>
            <prop-name>ignoreOnInsert</prop-name>
            <prop-type>java.lang.Boolean</prop-type>
            <prop-value>false</prop-value>
        </property>
    </column-properties>
    <property>
        <prop-name>datasource</prop-name>
        <propp-type>String</prop-type>
        <prop-value>serial://datasources/DataSource</prop-value>
    </property>
</table-properties>

This can be done in JBuilder:
1. Find the cross table in the Datasources screen.
2. Expand the table and right-click on each of the columns.
3. Choose Edit Column CMP Properties.
In this case the columns both have a datatype of java.math.BigDecimal.


#VisiBroker
#Security