Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PMR question on HF EJB book

 
Sean Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here is the query on page 415 of HF EJB book:

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.

Thanks so much.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sean Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

My question is that in HF EJB DD did not define how Director and Movie are related. I can relax if DD does define the relationship in DD.
 
Girija Siva
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sean Lee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()?

Thanks so much
 
Girija Siva
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Amit Delve
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also in the deployment descriptor for Director and Movie, the relationship is defined as one to many.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic