• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

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!!
0
Chapoor
Asked:
Chapoor
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now