Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / March 2007

Tip: Looking for answers? Try searching our database.

EJB 2.0: Compount Primary Keys and CMR

Thread view: 
Sascha Effert - 01 Mar 2007 14:16 GMT
Hello,

ist it possible with EJB 2.0 and 2 EJBs (CMP) with Compound Primary Keays to
use a CMR? I tried it with Netbeans 5.5 and JBoss 4.0.4. There I got
following error:

14:52:27,539 INFO  [BaseLocalProxyFactory] Bound EJB
 LocalHome 'StoragePoolBean' to jndi 'local/StoragePoolBean@26869040'
14:52:27,544 INFO  [ProxyFactory] Bound EJB Home 'StoragePoolBean' to
 jndi 'StoragePoolBean'
14:52:27,551 INFO  [BaseLocalProxyFactory] Bound EJB
 LocalHome 'VirtualVolumeBean' to jndi 'local/VirtualVolumeBean@31649249'
14:52:27,556 INFO  [ProxyFactory] Bound EJB Home 'VirtualVolumeBean' to
 jndi 'VirtualVolumeBean'
org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key
 mapped relationship must have key fields (or <primkey-field> is missing
 from ejb-jar.xml): ejb-relation-name=SP-contains-VVs

The Beans seem to be o.k., the CMR not. My config:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
   <display-name>mda2-EJBModule</display-name>
   <enterprise-beans>
       <entity>
           <display-name>StoragePoolEB</display-name>
           <ejb-name>StoragePoolBean</ejb-name>
           <home>de.virticalsolutions.vdrive.mda.StoragePoolRemoteHome
           </home>
           <remote>de.virticalsolutions.vdrive.mda.StoragePoolRemote
           </remote>
           <local-home>de.virticalsolutions.vdrive.mda.StoragePoolLocalHome
           </local-home>
           <local>de.virticalsolutions.vdrive.mda.StoragePoolLocal
           </local>
           <ejb-class>de.virticalsolutions.vdrive.mda.StoragePoolBean
           </ejb-class>
           <persistence-type>Container
           </persistence-type>
           <prim-key-class>de.virticalsolutions.vdrive.mda.StoragePoolPK
           </prim-key-class>
           <reentrant>false</reentrant>
           <abstract-schema-name>StoragePool</abstract-schema-name>
[...]
       </entity>
       <entity>
           <display-name>VirtualVolumeEB</display-name>
           <ejb-name>VirtualVolumeBean</ejb-name>
           <home>de.virticalsolutions.vdrive.mda.VirtualVolumeRemoteHome
           </home>
           <remote>de.virticalsolutions.vdrive.mda.VirtualVolumeRemote
           </remote>
           <local-home>
               de.virticalsolutions.vdrive.mda.VirtualVolumeLocalHome
           </local-home>
           <local>de.virticalsolutions.vdrive.mda.VirtualVolumeLocal
           </local>
           <ejb-class>de.virticalsolutions.vdrive.mda.VirtualVolumeBean
           </ejb-class>
           <persistence-type>Container</persistence-type>
           <prim-key-class>de.virticalsolutions.vdrive.mda.VirtualVolumePK
           </prim-key-class>
           <reentrant>false</reentrant>
           <abstract-schema-name>VirtualVolume</abstract-schema-name>
[...]
       </entity>
   </enterprise-beans>
   <relationships>
       <ejb-relation>
           <description/>
           <ejb-relation-name>SP-contains-VVs</ejb-relation-name>
           <ejb-relationship-role>
               <ejb-relationship-role-name>SPhasVV
               </ejb-relationship-role-name>
               <multiplicity>One</multiplicity>
               <relationship-role-source>
                   <ejb-name>StoragePoolBean</ejb-name>
                   </relationship-role-source>
               <cmr-field>
                   <cmr-field-name>virtualVolumes</cmr-field-name>
                   <cmr-field-type>java.util.Collection</cmr-field-type>
                   </cmr-field>
               </ejb-relationship-role>
           <ejb-relationship-role>
               <ejb-relationship-role-name>VVinSP
               </ejb-relationship-role-name>
               <multiplicity>Many</multiplicity>
               <relationship-role-source>
                   <ejb-name>VirtualVolumeBean</ejb-name>
                   </relationship-role-source>
               <cmr-field>
                   <cmr-field-name>storagePool</cmr-field-name>
                   </cmr-field>
               </ejb-relationship-role>
       </ejb-relation>
   </relationships>
   <assembly-descriptor>
[...]
   </assembly-descriptor>
</ejb-jar>

===========================================================================
The Primary Keys have no fields of the same name. I also tried to write the
mapping in the jbosscmp-jdbc. As you will see I used e relation-table, no
forign key. But with a forign-key I got the same result. Here is my
jbosscmp-jdbc.xml:

<jbosscmp-jdbc>
   <relationships>
       <ejb-relation>
           <ejb-relation-name>SP-contains-VVs</ejb-relation-name>
           <relation-table-mapping>
               <table-name>storagepool_has_virtualvolumes</table-name>
           </relation-table-mapping>
           <ejb-relationship-role>
               <ejb-relationship-role-name>SPhasVV
               </ejb-relationship-role-name>
               <key-fields>
                   <key-field>
                       <field-name>spID</field-name>
                       <column-name>storagepool</column-name>
                   </key-field>
                   <key-field>
                       <field-name>spSessionID</field-name>
                       <column-name>storagepool_session</column-name>
                   </key-field>
               </key-fields>
           </ejb-relationship-role>
           <ejb-relationship-role>
               <ejb-relationship-role-name>VVinSP
               </ejb-relationship-role-name>
               <key-fields>
                   <key-field>
                       <field-name>vvID</field-name>
                       <column-name>virtualvolume</column-name>
                   </key-field>
                   <key-field>
                       <field-name>vvSessionID</field-name>
                       <column-name>virtualvolume_session</column-name>
                   </key-field>
               </key-fields>
           </ejb-relationship-role>
       </ejb-relation>
   </relationships>
</jbosscmp-jdbc>

===========================================================================

It would be great if someone could explain me what is going wrong here. At
the moment I am thinking about not using CMR and make all the relationships
on my own. But I don't think that it's a good solution because it would be
much more code for me...

bests

Sascha Effert
Sascha Effert - 01 Mar 2007 14:39 GMT
> Hello,
>
[quoted text clipped - 32 lines]
>             </remote>
>            
<local-home>de.virticalsolutions.vdrive.mda.StoragePoolLocalHome
>             </local-home>
>             <local>de.virticalsolutions.vdrive.mda.StoragePoolLocal
[quoted text clipped - 25 lines]
>             <persistence-type>Container</persistence-type>
>            
<prim-key-class>de.virticalsolutions.vdrive.mda.VirtualVolumePK
>             </prim-key-class>
>             <reentrant>false</reentrant>
[quoted text clipped - 35 lines]
>     </assembly-descriptor>
> </ejb-jar>

===========================================================================
> The Primary Keys have no fields of the same name. I also tried to write
> the mapping in the jbosscmp-jdbc. As you will see I used e relation-table,
[quoted text clipped - 39 lines]
>     </relationships>
> </jbosscmp-jdbc>

===========================================================================

> It would be great if someone could explain me what is going wrong here. At
> the moment I am thinking about not using CMR and make all the
[quoted text clipped - 4 lines]
>
> Sascha Effert

Hello,

sorry: a short enhancement: With the relation table below I get the error:

org.jboss.deployment.DeploymentException: Both roles of a relation-table
 mapped relationship must have key fields:
 ejb-relation-name=SP-contains-VVs

The fieldnames in the jbosscmp-jdbc are the fields in the Primary Key
Classes.

bests

Sascha Effert


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.