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

Posted on 2004-11-25
Last Modified: 2013-11-24

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!!
Question by:Chapoor
    LVL 13

    Expert Comment

    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!

    Author Comment

    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 ???
    LVL 13

    Accepted Solution

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

    Author Comment

    will there be any Ejb application server (different vendors) that wont support this solution ( - ejb  with no pk and findbypk) ?

    LVL 13

    Expert Comment

    supposly all of them should support this

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now