0 Replies Latest reply on Jul 26, 2002 7:37 AM by Sven Buchwald

    JBoss CMR and foreign key's

    Sven Buchwald Newbie

      I've got the following problem:

      I have three Entity Beans and I need relationsships between these Beans.
      I need foreign keys, so that no one can delete Items in one of the tables if the Item is used in the other table.
      When I deploy them in JBoss all works fine, but I've got no foreign key's or something that seems to be a relation.
      I used XDoclet and Ant to generate my Beans.

      Here is a part from my first Bean class:

      * @jboss:relation
      * fk-column="iD_FK"
      * related-pk-field="iD_FK"
      * fk-constraint="true"
      *
      * @jboss:table-name table-name="ArtinTsuTable"
      *
      * @jboss:create-table create="true"
      *
      * @jboss:remove-table remove="false"
      *
      */

      ...

      /**
      * Retrieve the Tsu foreign-key
      *
      * @return Returns an int representing the foreign key of * this TSU
      *
      * @ejb:interface-method view-type="remote"
      *
      * @jboss:column-name name="iD_FK"
      *
      * @ejb:relation-name="Artintsu-Tsu"
      * role-name="one-Artintsu-has-one-Tsu"
      * target-role-name"one-Tsu-belongs-to-many-* Artintsu"
      * target-multiple="yes"
      **/
      public abstract Integer getTsuFK ();

      /**
      * set the Tsu foreign-key ID
      *
      * @param piD_FK The foreign-key of this Tsu.
      *
      * @ejb:interface-method view-type="remote"
      **/

      public abstract void setTsuFK (Integer iD_FK);

      Here is my ejb-jar.xml file generated by XDoclet:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

      <ejb-jar >

      No Description.
      <display-name>Generated by XDoclet</display-name>

      <enterprise-beans>

      <!-- Session Beans -->

      <![CDATA[Encapsulates the retrival of DB data]]>
      <display-name>Generates unique Identifier for an Entity</display-name>

      <ejb-name>test/SequenceGenerator</ejb-name>

      test.interfaces.SequenceGeneratorHome
      test.interfaces.SequenceGenerator
      <ejb-class>test.session.SequenceGeneratorBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>

      <env-entry>
      <env-entry-name>DataSource_Name</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>DefaultDS</env-entry-value>
      </env-entry>




      <![CDATA[Session Bean Template ATTENTION: Some of the XDoclet tags are hidden from XDoclet by adding a "--" between @ and the namespace.]]>
      <display-name>Bug TestSession Bean</display-name>

      <ejb-name>test/TestSession</ejb-name>

      test.interfaces.TestSessionHome
      test.interfaces.TestSession
      <ejb-class>test.session.TestSessionBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Container</transaction-type>

      <ejb-ref >
      <ejb-ref-name>ejb/mytest/TestEntity</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      test.interfaces.TestEntityHome
      test.interfaces.TestEntity
      <ejb-link>test/TestEntity</ejb-link>
      </ejb-ref>

      <resource-ref>
      <res-ref-name>test/Mail</res-ref-name>
      <res-type>javax.mail.Session</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>



      <!--
      To add session beans that you have deployment descriptor info for, add
      a file to your merge directory called session-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Entity Beans -->

      <![CDATA[No Description.]]>
      <display-name>Article Bean to store Products in Warehouse</display-name>

      <ejb-name>test/SbartinfBean</ejb-name>

      test.interfaces.SbartinfBeanHome
      test.interfaces.SbartinfBean

      <ejb-class>test.entity.SbartinfBeanCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ArticleTable</abstract-schema-name>
      <cmp-field >
      <![CDATA[Retrieve the Article Bean's id.]]>
      <field-name>iD_Article</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the Article's Description.]]>
      <field-name>description</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the Article Beans amount.]]>
      <field-name>amount</field-name>
      </cmp-field>
      <primkey-field>iD_Article</primkey-field>

      <env-entry>
      <env-entry-name>DataSource_Name</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>OracleDS</env-entry-value>
      </env-entry>




      <![CDATA[No Description.]]>
      <display-name>test/SbartintsuinfBean working on warehouse to support Article in TSU</display-name>

      <ejb-name>test/SbartintsuinfBean</ejb-name>

      test.interfaces.SbartintsuinfBeanHome
      test.interfaces.SbartintsuinfBean

      <ejb-class>test.entity.SbartintsuinfBeanCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>test.interfaces.SbartintsuinfBeanPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ArtinTsuTable</abstract-schema-name>
      <cmp-field >
      <![CDATA[Retrieve the SbartintsuinfBean id.]]>
      <field-name>iD_TSU</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the Article id.]]>
      <field-name>iD_Article</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the Article's Description.]]>
      <field-name>description</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the Article amount.]]>
      <field-name>amount</field-name>
      </cmp-field>

      <env-entry>
      <env-entry-name>DataSource_Name</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>OracleDS</env-entry-value>
      </env-entry>


      <query-method>
      <method-name>findAll</method-name>
      <method-params>
      </method-params>
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(aitt) FROM ArtinTsuTable AS aitt]]></ejb-ql>


      <query-method>
      <method-name>findArtinTSU</method-name>
      <method-params>
      <method-param>java.lang.Integer</method-param>
      </method-params>
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql><![CDATA[SELECT DISTINCT OBJECT (d) FROM ArtinTsuTable AS d WHERE d.iD_TSU = ?1]]></ejb-ql>





      <![CDATA[No Description.]]>
      <display-name>SbtsuinfBean working on warehouse to support TSU</display-name>

      <ejb-name>test/SbtsuinfBean</ejb-name>

      test.interfaces.SbtsuinfBeanHome
      test.interfaces.SbtsuinfBean

      <ejb-class>test.entity.SbtsuinfBeanCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>TsuTable</abstract-schema-name>
      <cmp-field >
      <![CDATA[Retrieve the TSU Bean's id.]]>
      <field-name>iD_TSU</field-name>
      </cmp-field>
      <primkey-field>iD_TSU</primkey-field>

      <env-entry>
      <env-entry-name>DataSource_Name</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>OracleDS</env-entry-value>
      </env-entry>




      <![CDATA[The Entity bean represents a TestEntity]]>
      <display-name>TestEntity working on projects to support clients</display-name>

      <ejb-name>test/TestEntity</ejb-name>

      test.interfaces.TestEntityHome
      test.interfaces.TestEntity

      <ejb-class>test.entity.TestEntityCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>test.interfaces.TestEntityPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>test/TestEntity</abstract-schema-name>
      <cmp-field >
      <![CDATA[Retrieve the TestEntity's id.]]>
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the TestEntity's FirstName.]]>
      <field-name>firstName</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the TestEntity's LastName.]]>
      <field-name>lastName</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the TestEntity's Password.]]>
      <field-name>password</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Retrieve the TestEntity's Email.]]>
      <field-name>email</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>address</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>city</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>zIP</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>state</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>country</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>creationDate</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>modificationDate</field-name>
      </cmp-field>

      <env-entry>
      <env-entry-name>SequenceName</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>TestEntity</env-entry-value>
      </env-entry>

      <ejb-ref >
      <ejb-ref-name>ejb/test/SequenceGenerator</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      test.interfaces.SequenceGeneratorHome
      test.interfaces.SequenceGenerator
      <ejb-link>test/SequenceGenerator</ejb-link>
      </ejb-ref>



      <!--
      To add entity beans that you have deployment descriptor info for, add
      a file to your merge directory called entity-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Message Driven Beans -->
      <message-driven >
      <![CDATA[Message Driven Bean Template]]>
      <display-name>Message Driven Test Bean</display-name>

      <ejb-name>test/TestMessage</ejb-name>

      <ejb-class>test.message.TestMessageDrivenBean</ejb-class>

      <transaction-type>Container</transaction-type>
      <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      <subscription-durability>NonDurable</subscription-durability>
      </message-driven-destination>

      </message-driven>

      <!--
      To add message driven beans that you have deployment descriptor info for, add
      a file to your merge directory called message-driven-beans.xml that contains
      the <message-driven></message-driven> markup for those beans.
      -->

      </enterprise-beans>

      <!-- Relationships -->

      <!-- Assembly Descriptor -->
      <assembly-descriptor >

      <!-- finder permissions -->

      <!-- finder permissions -->

      <method-permission >
      description not supported yet by ejbdoclet


      <ejb-name>test/SbartintsuinfBean</ejb-name>
      <method-name>findAll</method-name>
      <method-params>
      </method-params>

      </method-permission>

      <method-permission >
      description not supported yet by ejbdoclet


      <ejb-name>test/SbartintsuinfBean</ejb-name>
      <method-name>findArtinTSU</method-name>
      <method-params>
      <method-param>java.lang.Integer</method-param>
      </method-params>

      </method-permission>

      <!-- finder permissions -->

      <!-- finder permissions -->

      <!-- finder permissions -->

      <!-- finder permissions -->

      <!-- finder permissions -->

      <!-- transactions -->
      <container-transaction >

      <ejb-name>test/SbartinfBean</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction >

      <ejb-name>test/SbartintsuinfBean</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction >

      <ejb-name>test/SbtsuinfBean</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction >

      <ejb-name>test/TestEntity</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction >

      <ejb-name>test/SequenceGenerator</ejb-name>
      <method-intf>Remote</method-intf>
      <method-name>getNextNumber</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>

      <trans-attribute>Mandatory</trans-attribute>
      </container-transaction>

      <!-- finder transactions -->
      </assembly-descriptor>

      </ejb-jar>

      Hope for Help

      Thanks!!!