Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

cmr 1-many difficulty

Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a one to many relationship (unidirectional).

using a session bean facade I try the following:

1. create parent (batch header) entity (PK = batchNo)
2. create child (batch message) entities (PK = batchNo,SequenceNo)
End Loop

I am confused with a couple of things....

1. when calling the cmr method parent.getMessages(), I get an empty collection - where are my message entities?. They exist in the DB and my deployment descriptor *supposeably* defines a relationship.

(currently, I just call a finder on the child home entity and this works - but its not cmr!!)

2. do I have to "add" each child to the parent?
(eg parent.getMessages().add(child) ?

what does this do?, or better what is the container doing?

3. when I try to "add" I get the following error:
java.sql.SQLException: ORA-00936: missing expression

4. Most examples I have found show how to "get" the collection/related entities but dont show means for managing the relationship (eg updating, creating, removing)

5. I have read somewhere that the container creates a table in the database to manage relationships - is this true? Although my app deploys successfully, there is no "extra" table in the database.

6. In general, I assume you should just be able to get your parent entity (findByPrimaryKey) and call the get..() method returning a collection, so why the need to "add" the child in the first place.

Can someone please shed some light? and advise what the sql exception could be due to. I am happy with the ejb-jar.xml <relationship> - looks OK to me and pretty simple - so I can only think its my orion-ejb-jar.xml which is wrong.

I'm still confused though....thanks
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my project I have the same kind of relationship between NewsProvider and NewsSource.
Your ejb-jar.xml should contain something like:

To manage the CMR, you have indeed to set one of the CMR fields. Dependiing on whether the relationship is unidirectional or bidirectional (like mine), you will have one or two fields. In my exmaple, you can set (or add to) the newsSource collection or set the newsProvider field.
Here is an extract from NewsProviderBean, corresponding to your batch entity:

For a one-many relationship like yours and mine, there is no need for an extra table in the database, but there would be one for a many-many relationship.

As for the SQl exception, I have no clue...
Hope it helps.
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic