0 Replies Latest reply on May 7, 2003 1:19 AM by Thilko Richter

    Problem with cmr - one --> many

    Thilko Richter Newbie

      Hi!

      I have the following tables:
      Employee *-----belongs-to ------1 Group

      This is my jbosscmp-jdbc.xml:

      <ejb-name>EmployeeEntity</ejb-name>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <read-only>false</read-only>
      <table-name>SUR_Employee</table-name>

      <cmp-field>
      <field-name>firstname</field-name>
      <column-name>firstname</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>

      <jdbc-type>CHAR</jdbc-type>
      <sql-type>VARCHAR(32)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>createdBy</field-name>
      <column-name>CreatedBy</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>createdOn</field-name>
      <column-name>CreatedOn</column-name>

      <jdbc-type>DATE</jdbc-type>
      <sql-type>DATE</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>changedBy</field-name>
      <column-name>ChangedBy</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>changedOn</field-name>
      <column-name>ChangedOn</column-name>

      <jdbc-type>DATE</jdbc-type>
      <sql-type>DATE</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>team</field-name>
      <column-name>tem_id</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>lastname</field-name>
      <column-name>lastname</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>phone</field-name>
      <column-name>phone</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>eMail</field-name>
      <column-name>Mail</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>phonePrv</field-name>
      <column-name>PhonePrv</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(20)</sql-type>

      </cmp-field>

      <!-- merge point: jbosscmp-jdbc-load-{0}.xml -->




      <ejb-name>TeamEntity</ejb-name>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <read-only>false</read-only>
      <table-name>SUR_Team</table-name>

      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>createdBy</field-name>
      <column-name>CreatedBy</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>createdOn</field-name>
      <column-name>CreatedOn</column-name>

      <jdbc-type>DATE</jdbc-type>
      <sql-type>DATE</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>changedBy</field-name>
      <column-name>ChangedBy</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>changedOn</field-name>
      <column-name>ChangedOn</column-name>

      <jdbc-type>DATE</jdbc-type>
      <sql-type>DATE</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>department</field-name>
      <column-name>fb</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>escalation</field-name>
      <column-name>escalation</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>onDutyCall</field-name>
      <column-name>rufbereitschaft</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>eMail</field-name>
      <column-name>mail</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(30)</sql-type>

      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>description</column-name>

      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(300)</sql-type>

      </cmp-field>

      <!-- merge point: jbosscmp-jdbc-load-{0}.xml -->



      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>Team-Employee</ejb-relation-name>
      <foreign-key-mapping/>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Team-has-escalation</ejb-relationship-role-name>
      <fk-constraint>true</fk-constraint>
      <key-fields/>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Employee-is-escalation</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>escalation</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>Employee-Team</ejb-relation-name>
      <foreign-key-mapping/>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Employee-has-Team</ejb-relationship-role-name>
      <key-fields/>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Team-has-Employees</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name>tem_id</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      </ejb-relation>


      </jbosscmp-jdbc>

      ---------------------------------------------------------------------------------------------


      and my ejb-jar.xml:
      ...

      <![CDATA[]]>
      <display-name>Employee Entity</display-name>

      <ejb-name>EmployeeEntity</ejb-name>

      de.talkline.picasso.interfaces.EmployeeEntityRemoteHome
      de.talkline.picasso.interfaces.EmployeeEntityRemote
      <local-home>de.talkline.picasso.interfaces.EmployeeEntityLocalHome</local-home>
      de.talkline.picasso.interfaces.EmployeeEntityLocal

      <ejb-class>de.talkline.picasso.server.EmployeeEntity</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>EmployeeEntity</abstract-schema-name>
      <cmp-field >
      <![CDATA[]]>
      <field-name>firstname</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>createdBy</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>createdOn</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>changedBy</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>changedOn</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>team</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>lastname</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>phone</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>eMail</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>phonePrv</field-name>
      </cmp-field>
      <primkey-field>id</primkey-field>


      <query-method>
      <method-name>findEmployeeByTeam</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql><![CDATA[SELECT OBJECT(a) FROM EmployeeEntity AS a WHERE a.team.name = ?1 ]]></ejb-ql>

      <!-- Write a file named ejb-finders-EmployeeEntity.xml if you want to define extra finders. -->

      ...
      <ejb-relation >
      <ejb-relation-name>Employee-Team</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>Employee-has-Team</ejb-relationship-role-name>
      Many
      <relationship-role-source >
      <ejb-name>EmployeeEntity</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>team</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>Team-has-Employees</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>TeamEntity</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>

      </ejb-relation>
      ....
      ------------------------------------------------------------------------


      It seems that the findByTeam() on the EmployeeEntity suceed, but when I try to access the EmployeeEntities I get this error message: (includes the findByTeam() method call:

      2003-05-07 09:05:11,721 TRACE [org.jboss.ejb.plugins.LogInterceptor] Start method=findEmployeeByTeam

      2003-05-07 09:05:11,721 DEBUG [org.jboss.ejb.plugins.LogInterceptor] InvokeHome: findEmployeeByTeam(Festnetz)

      2003-05-07 09:05:11,721 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] Current transaction in MI is TransactionImpl:XidImpl [FormatId=257, GlobalId=tl-00934//5, BranchQual=]

      2003-05-07 09:05:11,721 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TX_REQUIRED for findEmployeeByTeam

      2003-05-07 09:05:11,721 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] Thread came in with tx TransactionImpl:XidImpl [FormatId=257, GlobalId=tl-00934//5, BranchQual=]

      2003-05-07 09:05:11,721 TRACE [org.jboss.ejb.plugins.EntityInstancePool] Get instance org.jboss.ejb.plugins.EntityInstancePool@267b76#true#class de.talkline.picasso.server.EmployeeEntity

      2003-05-07 09:05:11,731 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.EmployeeEntity.findEmployeeByTeam] Executing SQL: SELECT t0_a.id FROM SUR_EMPLOYEE t0_a, SUR_TEAM t1_a_team WHERE (t1_a_team.name = ?) AND (t0_a.tem_id=t1_a_team.id)

      2003-05-07 09:05:11,751 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TxInterceptorCMT: In finally

      2003-05-07 09:05:11,751 TRACE [org.jboss.ejb.plugins.LogInterceptor] End method=findEmployeeByTeam

      2003-05-07 09:05:11,751 INFO [STDOUT] Hallo

      2003-05-07 09:05:11,751 INFO [STDOUT] $Proxy57

      2003-05-07 09:05:11,751 INFO [STDOUT] Hallo2

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.LogInterceptor] Start method=getLastname

      2003-05-07 09:05:11,781 DEBUG [org.jboss.ejb.plugins.LogInterceptor] Invoke: [31] getLastname()

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] Current transaction in MI is TransactionImpl:XidImpl [FormatId=257, GlobalId=tl-00934//5, BranchQual=]

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TX_REQUIRED for getLastname

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] Thread came in with tx TransactionImpl:XidImpl [FormatId=257, GlobalId=tl-00934//5, BranchQual=]

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.EntityLockInterceptor] Begin invoke, key=31

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.EntityInstancePool] Get instance org.jboss.ejb.plugins.EntityInstancePool@267b76#true#class de.talkline.picasso.server.EmployeeEntity

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.AbstractInstanceCache] Activated bean EmployeeEntity with id = 31

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy] entryAdded, entry=key: 31, object: 154145, entry: 17035c6

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.EntityInstanceInterceptor] Begin invoke, key=31

      2003-05-07 09:05:11,781 TRACE [org.jboss.ejb.plugins.EntitySynchronizationInterceptor] invoke called for ctx org.jboss.ejb.EntityEnterpriseContext@154145, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=tl-00934//5, BranchQual=]

      2003-05-07 09:05:11,781 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.EmployeeEntity] Executing SQL: SELECT firstname, CreatedBy, CreatedOn, ChangedBy, ChangedOn, tem_id, lastname, phone, Mail, PhonePrv, tem_id FROM SUR_EMPLOYEE WHERE (id=?)

      2003-05-07 09:05:11,811 TRACE [org.jboss.ejb.plugins.EntitySynchronizationInterceptor] loadEntity Exception, clear tx for ctx=org.jboss.ejb.EntityEnterpriseContext@154145, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=tl-00934//5, BranchQual=]

      2003-05-07 09:05:11,811 TRACE [org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy] entryRemoved, entry=key: null, object: null, entry: 17035c6

      2003-05-07 09:05:11,811 TRACE [org.jboss.ejb.plugins.EntityInstanceInterceptor] Ending invoke, exceptionThrown, ctx=org.jboss.ejb.EntityEnterpriseContext@154145

      2003-05-07 09:05:11,811 TRACE [org.jboss.ejb.plugins.EntityInstanceInterceptor] End invoke, key=31, ctx=org.jboss.ejb.EntityEnterpriseContext@154145

      2003-05-07 09:05:11,811 TRACE [org.jboss.ejb.plugins.EntityLockInterceptor] End invoke, key=31

      2003-05-07 09:05:11,811 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TxInterceptorCMT: In finally

      2003-05-07 09:05:11,811 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException, causedBy:

      java.sql.SQLException: Got a java.lang.String[cl=0, value=10] while looking for a de.talkline.picasso.interfaces.TeamEntityLocal[cl=28301772]

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.coerceToJavaType(JDBCUtil.java:570)

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.getResult(JDBCUtil.java:437)

      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadArgumentResults(JDBCAbstractCMPFieldBridge.java:359)

      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.loadInstanceResults(JDBCAbstractCMPFieldBridge.java:312)

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:147)

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:62)

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:572)

      at org.jboss.ejb.plugins.CMPPersistenceManager.loadEntity(CMPPersistenceManager.java:410)

      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.loadEntity(CachedConnectionInterceptor.java:353)

      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:251)

      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)

      at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:90)

      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:163)

      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)

      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)

      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)

      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)

      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)

      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)

      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)

      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)

      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:301)

      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)

      at $Proxy57.getLastname(Unknown Source)

      at de.talkline.picasso.server.EmployeeHandler.getEmployeeList(Unknown Source)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:324)

      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:660)

      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)

      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)

      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)

      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)

      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)

      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)

      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)

      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:313)

      at org.jboss.ejb.Container.invoke(Container.java:712)

      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)

      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)

      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)

      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)

      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)

      at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:111)





      Do I Have to do something on the *blind* side of the relationship? Please, I need help!


      Thanks a lot!


      Thilko