• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

MovieBean in HFEJB p396

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you declare directorId as cmp field for the Director entity
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you tell us what value is being returned from the findByPrimaryKey() method.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic