EJB - help me with a simple CMR - please!!


Please Im pretty new to CMR and appreciate if you could help me answer a simple question.

Database model:
ID___ Name


I ve two CMP entities: WriterBean and BookBean

I ve set the relations between Writer and Books, and it works as far as a writer only has one book.
That because I set the FK also as a PK to the BookBean. And when I try to create next book for a writer it fails with duplicate-exception, logicaly.

Can I solve this without any need of specifing a primary key for books at all?
How is CMP handling no-pk entity and is relations working without any pk?
Do EJB vendors manage no pk ejbs? what about ejb restrictions.

I ve read that there must be a primary key, but not necessery a database field - HOW? could you please explain!

Please this is very urgent and I Thank you very much!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

there must be a prmary key for books, why u just add an automatic or sequence field to BookTbl? this will be the easiest way
if this is not applicable then ur BookBean have to be revereted to BMP Model, thats it!
ChapoorAuthor Commented:
IMO, the autoinc fields are more problematic then they actully solve.

Is this so difficult to reach with EJB ???

How do you solve this?
2 CMP entities.
1 has no Database primary key field, but a FK of the other table,

I mean
One writer has many books, and books no pk in database.

How to program this in 2 CMP ? with CMR.

Simple issue and so hard to solve with EJB ???
try this:

ok try this:
1- from ur ejb-jar.xml BookBean descriptor remove this line:


2- remove this from BookHome interface
 public KbItemAttachmentLocal findByPrimaryKey(Long id) throws

3- create at least one another finder (like findAll() )

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChapoorAuthor Commented:
will there be any Ejb application server (different vendors) that wont support this solution ( - ejb  with no pk and findbypk) ?

supposly all of them should support this
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.