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

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top