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

Hi!

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

Database model:
WriterTbl
ID___ Name
1____RodJohnson
2____PankajKumar

BookTbl
FK___Name
1____J2EE-DesignAndDevelopment
1____ProfessionalJSP
2____J2EESecurity

Question:
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!!
ChapoorAsked:
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.

petmagdyCommented:
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!
0
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 ???
0
petmagdyCommented:
try this:

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

      <primkey-field>id</primkey-field>

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

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

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) ?

thanks
0
petmagdyCommented:
supposly all of them should support this
0
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.