File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186

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>
<relationship-role-source >
<cmr-field >
<ejb-relationship-role > <ejb-relationship-role-name>EnqCartMaster-has-many-EnqCartDetails</ejb-relationship-role-name>
<relationship-role-source >
<cmr-field >
<cmr-field-name>enqDetail</cmr-field-name> <cmr-field-type>enqcartdetail.interfaces.EnqCartDetailData[]</cmr-field-type>
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(
at org.jboss.metadata.XmlFileLoader.load(
at org.jboss.ejb.EJBDeployer.create(

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


********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.
I agree. Here's the link:
subject: What are valid cmr-field types for EJB2.0 Spec???
It's not a secret anymore!