EJB3/JPA and versioning



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

.



Relevant Pages

  • [SWT] SWT-Alternative zu ContainerListener
    ... Ich versuche gerade in Eclipse ein spezielles Composite zu entwickeln, in welchem der Benutzer Komponenten selbst verschieben und vergrößern bzw. verkleinern kann. ... Habe ich versucht, jedoch wird dem Layout nicht mitgeteilt, wenn Komponenten in meinem COmposite verschoben oder resized werden. ... Dafür gibt es ControlListener, jedoch muss ich den Anzeigeelementen erst einmal diese Listener zuweisen. ...
    (de.comp.lang.java)
  • RE: Forecast Table
    ... What is the Primary Key for this table? ... forecast is set at product customer level. ... What do you think about the following table layout in Access 2003? ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Layout Hell
    ... > Could I have some help with this layout? ... > I am new to the layout scene, but if I could see some real examples, I might ... Normal record layouts similar to this have been in very successful use ... you can't define a primary key as more than one ...
    (comp.lang.cobol)