EJB3/JPA and versioning

G

guigouz

Hello, I'm thinking about a structure which starts as simple as

Book hasMany Page

But Page is not an ordinary entity, it's primary key is composite, and
has (id, version). Everytime I save a Page, it doesn't update it, but
instead increments version and saves it (same id).
Now when I fetch a Book, it should return all Pages, at their lastest
versions. So, the table layout would look like the following, if we
imagine 3 pages

page_id, version, content
1 1 *
1 2 **
1 3 *
2 1 ###
3 1 ##
3 2 &&&&

To add a bit more complexity, a Page may belong to more than one book.
So, for two Books, I'd have a book_pages table with

book_id, page_id
1 1
1 2
2 1
2 3

This way Book 1 has pages { 1, 2 }, and book 2 has pages { 1, 3}. For
the versioning

- When I findByBookId(1) i'd get pages { (1,3), (2,1) } - Page 1
Version 3, Page 2 version 1
- When I findByBookId(2) i'd get pages { (1,3), (3,2) } - Page 1
Version 3, Page 3 version 2

Or, every page on their lastest version. I guess it's pretty close to
what ThingDB from the Open Library project offers (altough they use
python). More info at http://demo.openlibrary.org/about/tech

Anyone think it would be possible to implement such layout using JPA ?
Or maybe I should stick to plain JDBC with custom DAOs ?

Thanks a lot

Gui

Questions I'd like to discuss
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top