• Post Reply Bookmark Topic Watch Topic
  • New Topic

cmr 1-many difficulty  RSS feed

Paul Strachan
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
Bruno Collet
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!