EJB3 Composite Primary Key based on EJB references' key

A

Anon

Hi,

I'm trying to find a way to write an entity EJB that would have, as a
primary key, a key composed with 2 other keys which are the PK of 2
others EJB.

Example:

2 entities:
- Book <entity EJB><pk=bookId>
- Subscriber <entity EJB><pk=subscriberId>

1 entity:
- Borrow<entity EJB><pk=bookId,subscriberId>

I know that I can write a BorrowPK containing two fields as a primary
key, but this is not what I want to do.

I want the Borrow entity to have 3 fields:
@EJB Book book;
@EJB Subscriber subscriber;
@Temporal Date date;

and the book/subscriber couple would be the primary key.

The interest of all this is to save database space, and execution time
by not creating a useless "BorrowId" which would be the primary key
field. The other interest would be that we'd have a direct access to
the referenced EJB from the Borrow entity. (ie: borrow.getBook() or
borrow.getSubscriber())

Any idea how I can do that ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top