SELECT DISTINCT OBJECT (d) FROM DirectorSchema d, IN (d.movies) m WHERE m.genre = 'Horror'
How does container find out all movies belonged to each director?
DD on page 395 only defines that there is relationship between director and movie bean, but it does not say how these two are related. Of course they are related by directorid key in the database, but this relationship is not defined in DD.
EJB-QL corresponds to the information you present in your deployment descriptors. The wonderful thing about EJB is that you can define things like this in your deployment descriptors, and let your container worry about the crazy details you're worrying about here. Just take a deep breath and relax--EJB is taking care of it for you.
If you must know though, most EJB containers will have some default way of creating mapping your entity beans into some persistent storage if you don't tell it how to do it. For instance, JBoss will allow you to present a bunch of information in a deployment-descriptor-like file named jboss-jdbccmp.xml (I forget--the name of the file is close to that). However, how you map entity beans into storage shouldn't (or very rarely) influence how you setup your CMR and CMP fields.
Trying to explian it , Anyone thinks otherwise or want to add more.... Please share it...
Note that he directorId is passed at the time of creation of bean to create()method as a parameter, and the setter to set the Director cmr-field is called in ejbPostCreate(). The --getter and setter on cmr-field in the bean and --the declaration of the relationship in DD together say that Movie has Director. This is all Abstact. The actual mapping of the directorId to a perticular column in a particular database table is container specific. The container provides tools to map these value. It is all confusing the first time BUT remember the developer works on abstract things as he don't know where exactly the bean will be used.The mapping is specific to where the bean is used or deployed Also note the naming conventions between the cmr-field-name and the getter and setter of that field Hope this is of any help Thanks
Now I seem to understand how movie and director are related. The relationship is defined in MovieBean code in page 396:
Director dir =dirHome.findByPrimaryKey(directorID); setDirector(dir);
This clearly shows Movie and Director are related through directorID.
Here is another related question. In page 396, how is the new movie record created with directorID even though there is no setDirectID() abstract method in ejbCreate()?
Follow the life cycle of entity bean closely and that should lead u to the answer. ejbPostCreate() is part of the entity bean create process. It is the second chance for the bean to initialize itself remember??