Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MovieBean in HFEJB p396

 
Suman Sarker
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Sarker
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you declare directorId as cmp field for the Director entity
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us what value is being returned from the findByPrimaryKey() method.
 
T Rob Darrough
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic