• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA create new record version instead of Merging (update)

 
nicolas diogo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

as you can expect, I am a newbe to JPA, and really stuck as well.

I have a requirement for a web app that needs to maintain all versions that have been created.
like having an article's table where every iteration of content changes need to be kept for future reference.

for instance my table might be like:

create table t_articles(

article_id int primary key

, article_content_id int not null
, article_version int not null

, article_published bit

, article_title varchar(64) not null
, article_content_txt varchar(4000)

, created_by int
, created_dt datetime
, valid_until datetime

)

this table will have a unique index on:
article_content_id
article_version

we can have the same article (article_content_id) with multiple revisions (article_version)


and there is also a check to ensure that:
only ONE record article_content_id has article_published set to true (this is the record that will be shown on the webpage)

i imaged that i can be done by creating the correct logic within a method.
but i am not certain about how to control the transactions.
does it mean that i have to change the transaction from being container controlled to be application controlled?

i would appreciate some insights on this question

thanks,


Nicolas
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want versioning of your entities than check out Hibernate Envers.
 
nicolas diogo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Wouter,

i am using EclipseLink - your suggestion implies that i have to start using Hibernate and add this extension to it as well.

and i am not sure about hibernate compliance with JPA standards - as i understand it uses its own configuration files (xml).


thanks for the input.

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't suggest to use anything. I just suggested to look at Hibernate Envers. Of course there are always 1001 solutions to a problem.

You can use hibernate as a JPA provider and still get access to hibernate specific features.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EclipseLink has support for history in the base product.

See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/History

 
nicolas diogo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James,


i will build a test app to wrap my head around the concept.
but it seem to do the trick at first glance.

thanks for taking the time to assist me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic