aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes What are valid cmr-field types for EJB2.0 Spec??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "What are valid cmr-field types for EJB2.0 Spec???" Watch "What are valid cmr-field types for EJB2.0 Spec???" New topic
Author

What are valid cmr-field types for EJB2.0 Spec???

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
Hi,

I have 2 CMP beans in which I want to set 1-N relationship. My mapping in EJB-jar.xml for relationship is as follows:-
=========================
<ejb-relation > <ejb-relation-name>EnqCartMaster-to-EnqCartDetail</ejb-relation-name>
<ejb-relationship-role > <ejb-relationship-role-name>EnqCartDetail-has-one-EnqCartMaster</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete/>
<relationship-role-source >
<ejb-name>EnqCartDetail</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>enqCartMaster</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role > <ejb-relationship-role-name>EnqCartMaster-has-many-EnqCartDetails</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>EnqCartMaster</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>enqDetail</cmr-field-name> <cmr-field-type>enqcartdetail.interfaces.EnqCartDetailData[]</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
=========================
In above EnqCartDetailData is my ValueObject Class.
Now my question is can I use "<cmr-field-type>" as "enqcartdetail.interfaces.EnqCartDetailData[]" instead of Collection or set?
In above cmr-type("enqcartdetail.interfaces.EnqCartDetailData[]") when I am trying to deply EJB it gives me error as follows:-
=====================
org.jboss.deployment.DeploymentException: Error in ejb-jar.xml for relation EnqCartMaster-to-EnqCartDetail: cmr-field-type should be java.util.Collection or java.util.Set but is econify.enqcartdetail.interfaces.EnqCartDetailData[]
at org.jboss.metadata.ApplicationMetaData.importEjbJarXml(ApplicationMetaData.java:447)
at org.jboss.metadata.XmlFileLoader.load(XmlFileLoader.java:151)
at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:495)
........
=====================

Please tell me instead of Collection & Set , Can I use valueObjects array as cmr-field type??

Thanks
Prash.


********Deserve Before You Desire********
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
I'm not a 100% sure, but I really think you have to use Collections or Sets, as the error message indicated.

I think it's true at least with EJB 2.x (I'm not sure about the new EJB 3.0 spec, which is very diffrent).

Theres a good reason for it:
With component-managed relationships, the whole idea is that the Application Server (JBoss) has to know about every action that you do, that affects the relationship ! For example, if you remove something from the Collection, JBoss has to know about it, and generate the appropriate SQL to fix the database.
Now, since Collection (and Set) is in *interface*, JBoss can inject its own implementation into your entity bean. That special JBoss Collection notifies JBoss every time you call Collection.add(), Collection.remove(), etc. That's how JBoss knows it should bix the data base.

You can actually see it in action... run any code that has CMR using Collections. Now, when you get the collection, call 'getClass()' to see which concrete class it is... it would be some JBoss class.

Anyway, when you use simple arrays (as you suggested), JBoss can't do this trick, because array is not a java *interface*, so it's difficult to replace its implementation to be notified whenever the array changes...

Even if some vendor managed to work around it (with some low-level byte code tricks), it would still be against the spec.
 
wood burning stoves
 
subject: What are valid cmr-field types for EJB2.0 Spec???