java - Expressing Audit functionality with JPA annotations -


i'm in middle of fumbling around jpa. i've far created entity representing user data , stateless bean access user data.

the data users can work on (sqlfiddle link):

create table data (   email character varying(128) not null,   data character varying(128) not null,   lastchange timestamp not null,   constraint email_data primary key (email,data) ); 

the idea save unaltered, current version users empty email key. then, when user alters data , creates auditable version, email field filled users email. way, each user can alter copy of data. merging problem later date , not part of question.

now, have entities in place. created stateless bean load/save/find data records using entitymanager. logic load user specific version first, load unaltered version if user has no user specific version still eludes me.

consider part of bean:

@stateless public class databean {      @persistencecontext(unitname = "authpu")     private entitymanager em;      public list<dataentry> findall() {         typedquery<dataentry> query = em.createquery("select d data d", dataentry.class);         list<dataentry> list = query.getresultlist();         return query.getresultlist();     }      ... } 

how inject user information class? need data current user first, data users if there's no user-specific data available.

you use standard ejb authentication. can call sessioncontext.getcallerprincipal() in session bean user id. use user id query database.

in case have add column table (containing user id), if authentication user id not equal email address.

far simpler (but less elegant) add email address arguments of ejb service method: make part of public api.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -