Meaningless Drivel is fun!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes MovieBean in HFEJB p396 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "MovieBean in HFEJB p396" Watch "MovieBean in HFEJB p396" New topic
Author

MovieBean in HFEJB p396

Suman Sarker
Ranch Hand

Joined: May 06, 2004
Posts: 68
Hi All,
I tried to create the Movie bean showed in page 396 of HFEJB. I also created the Director Bean. The Director Bean is working fine, I can create or remove directors from the database. But the problem is with the Movie Bean. Whenever I try to insert a new movie in the database, JBoss shows the following error

14:03:21,771 ERROR [MovieBean] Could not create entity
java.sql.SQLException: General error, message from server: "Column 'DirectorID' cannot be null"

Following is the code snippet from my Movie Bean



I dont know what to do as this is my first attempt in creating an Entity Bean. Please help me.

Thanks
Suman


Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
Suman Sarker
Ranch Hand

Joined: May 06, 2004
Posts: 68
After a lot of experiment, I found out that I need the CMP field "directorId" to get the bean working. But the book says(page 400) that, the "directorId" field should not be declared because we already have a CMR field for director.
But I could not make the MovieBean work without declaring the CMP field for directorId.
Am I doing something wrong?
Girija Siva
Ranch Hand

Joined: Apr 23, 2004
Posts: 41
Did you declare directorId as cmp field for the Director entity
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Can you tell us what value is being returned from the findByPrimaryKey() method.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
T Rob Darrough
Greenhorn

Joined: Apr 30, 2004
Posts: 11
I have had similiar experiences. If I don't put the directorId field in Movie the container will not generate anything similiar (i.e. a foriegn key in Movie to Director). If I do put directorId into Movie then the container will not manage it.
Suman Sarker
Ranch Hand

Joined: May 06, 2004
Posts: 68
Hi All,

Hi Girija,
I did declare "directorId" as cmp field for the Director entity. Here is the DirectorBean



Hi Roger,
Here is the findByPrimaryKey() method from my MovieHome interface



Hi Rob,
How did you get around this problem?

Thanks
Suman
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Ah, maybe I didn't make my question clear. I'm asking what value is returned from this at runtime.

Director director = directorHome.findByPrimaryKey(directorId);

I'm wondering if it is returning null, thus causing the problem when inserting the DirectorID field into the DB.
Suman Sarker
Ranch Hand

Joined: May 06, 2004
Posts: 68
Hi Roger,
Line 16 in the following code snippet is never executed as it is in ejbPostCreate() and I get the exception from ejbCreate() method. I was able to verify it because I saw the following in JBoss console


Here is code snippet from my MovieBean class. Please note that, the MovieBean works fine if I keep line #8, line #29, line #30 and add the cmp field "directorId" in the xml files.


[ May 24, 2004: Message edited by: Suman Sarker ]
Sean Lee
Greenhorn

Joined: May 02, 2004
Posts: 6
Hi Kathy or other moderators,

please help us to clarify this issue? Whether we direcotrID CMP and related set method in order to insert movie record with directorID? Thanks.


OCP. SCJP(1.4)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MovieBean in HFEJB p396