0 Replies Latest reply on Nov 9, 2005 1:22 PM by Guilherme Melo e Maranhão

    Relationships in EJB 2.1 with CMP ??

    Guilherme Melo e Maranhão Newbie

      Hi guys,

      JBoss throws this exception when it deploys my application:

      16:01:49,946 WARN [ServiceController] Problem starting service jboss.j2ee:jndiName=Conta,service=EJB
      org.jboss.deployment.DeploymentException: Configuration found in jbosscmp-jdbc.xml for relation Operacao-Conta but relation is not a jbosscmp-jdbc-managed relation in ejb-jar.xml
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.(JDBCApplicationMetaData.java:465)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXmlFileLoader.java:67)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaData(JDBCStoreManager.java:721)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.initStoreManager(JDBCStoreManager.java:409)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:353)
      at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:157)
      at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:340)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:287)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:236)
      at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)

      Here are my entity beans and relationship settings in ejb-jar.xml:

      ...


      <ejb-name>Conta</ejb-name>
      sistemaBancario.ejb.entityBeans.conta.ContaHome
      sistemaBancario.ejb.entityBeans.conta.Conta
      <ejb-class>sistemaBancario.ejb.entityBeans.conta.ContaBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>sistemaBancario.ejb.entityBeans.conta.ContaPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ContaCMP</abstract-schema-name>
      <cmp-field><field-name>agencia</field-name></cmp-field>
      <cmp-field><field-name>conta</field-name></cmp-field>
      <cmp-field><field-name>senha</field-name></cmp-field>
      <cmp-field><field-name>nomeCliente</field-name></cmp-field>
      <cmp-field><field-name>saldo</field-name></cmp-field>



      <ejb-name>Operacao</ejb-name>
      sistemaBancario.ejb.entityBeans.operacao.OperacaoHome
      sistemaBancario.ejb.entityBeans.operacao.Operacao
      <ejb-class>sistemaBancario.ejb.entityBeans.operacao.OperacaoBean</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>OperacaoCMP</abstract-schema-name>
      <cmp-field><field-name>id</field-name></cmp-field>
      <cmp-field><field-name>descricao</field-name></cmp-field>
      <primkey-field>id</primkey-field>



      <ejb-relation>
      <ejb-relation-name>Operacao-Conta</ejb-relation-name>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Conta-possui_Operacoes</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Conta</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>colOperacoes</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Operacoes-da-Conta</ejb-relationship-role-name>
      Many
      <cascade-delete />
      <relationship-role-source>
      <ejb-name>Operacao</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>conta</cmr-field-name>
      <cmr-field-type>sistemaBancario.ejb.entityBeans.conta.Conta</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>

      ...

      Here are my relationship settings in standardjbosscmp.xml:

      ...
      <enterprise-beans>

      <!-- Exemplo de Relacionamento -->

      <ejb-name>Conta</ejb-name>
      <table-name>Conta</table-name>
      <cmp-field>
      <field-name>agencia</field-name>
      <column-name>agencia</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>conta</field-name>
      <column-name>conta</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>senha</field-name>
      <column-name>senha</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>nomeCliente</field-name>
      <column-name>nomeCliente</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>saldo</field-name>
      <column-name>saldo</column-name>
      </cmp-field>


      <ejb-name>Operacao</ejb-name>
      <table-name>Operacao</table-name>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>descricao</field-name>
      <column-name>descricao</column-name>
      </cmp-field>


      </enterprise-beans>



      <ejb-relation>
      <ejb-relation-name>Operacao-Conta</ejb-relation-name>
      <foreign-key-mapping/>

      <!-- A critical thing to note is the key-fields element that defines the mapping between the primary key
      field "id" and the foreign key column "idDepartamento". This definition is placed in the
      ejb-relationship-role element for the "One" side of the relationship; in other words on the role that
      corresponds to the primary key side and not on the role where the foreign key columns are located.
      -->

      <ejb-relationship-role>
      <ejb-relationship-role-name>Conta-possui_Operacoes</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>agencia</field-name>
      <column-name>agencia</column-name>
      </key-field>
      <key-field>
      <field-name>conta</field-name>
      <column-name>conta</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Operacoes-da-Conta</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>id</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>

      ...

      It is a 1:N relationship between the entity beans Conta and Operacao. The entity bean Conta contains a Collection of Operacao.

      Is the mistake in ejb-jar.xml, standardjbosscmp.xml or both?

      If someone could help, I'd appreciate very much!

      Thanks, Guilherme