This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

cmr 1-many difficulty

 
Greenhorn
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)
Loop
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic