How to record entity changes

Hi friends,
I am trying to implement feature which should record entity property changes. Basicaly I want to keep history when and what has changed in a separate table.
For example having a table similar to this and record all changes made to entities
Entity_ID, ENTITY, old_property_value, new_property_value.
Is it an easier way to achieve this using Persistence unit, rather than adding extra logic to each setters?
To better illustrate my problem here is simple example. Assume we have a simple entity class like
@Entity
public class UserEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String fullName;
    public long getId() {
        return id;
    public void setId(long id) {
        this.id = id;
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }Assume we call
myEntity.setFullName("New Name");And persisting changes should add record to separate table
ID ENTITY        OLD_VALUE    NEW_VALUE
1  UserEntity     Old Name    New NameI can simply add extra logic to setter or create a wrapper/controller classes but maybe there is an easier way to achieve this?
I am using glassfish application server.
Thank you for your help!

it depends how "efficient" you want the code to be. with some fairly straightforward JPA-only code, you could write a PostLoad hook method which recorded the current state of the entity in some sort of internal map (using the persistence annotations so that the code was not entity specific). then you could write a PrePersist hook method which takes the original state (as recorded by the PostLoad hook method) and compares it to the current state, and records any changes to your updates table. you could pile all of this into some common base class for all your persistent entities and you would be good to go. like a said, fairly straightforward to code, may not be super efficient at runtime.
probably the most efficient way to do this would be to use some sort of aspect oriented programming/byte code manipulation to automagically annotate all the setter methods to record updates in realtime to an internal updates map. then, a similar PrePersist hook can just use this updates map to record the updates to the appropriate table. again, you can most of this in a common base object type and then manipulate the byte code at some point to insert the setter hooks. a variation on this technique, if you didn't want to go the aspect oriented route, would be to manually insert the setter hook code into every setter method. pain in the butt to maintain, but sticks to builtin JPA functionality.

Similar Messages

  • How to record the change in build of an assembly for a shipped machine

    Hi all
    My client manufactures assemblies (configuration items for a model) which consume serialized components.
    These components can be replaced by the Field Engineer when they visit the customer site.
    My client wants to record the change in configuration of a model because of this transaction.
    They have Install Base configured but do not use Depot Repair or Field Service
    Is it possible to record the change in configuration of the assembly that has been shipped to a customer?
    Do they need to have Depot Repair or some other module for this?
    Can this be done using Install Base only?
    Please advice.
    Regards
    Akhil
    [email protected]

    Hi,
    Depot repair is not required, if you want to just track the items. Installbase must be enough. field Service will be to track the SR's if that serves your purpose.
    All installbase updates happen through Inventory transactions. So important trggers will be RMA, WIP Issues and Receipts, PO receipts etc.
    Depot repair is to properly execute the after sales service when the repair needs to happen in your work shop. If you are fine to manage this part of transactions manually you do not need Depot repair.
    regards,

  • How can we get changed records in delta in case of numeric pointer

    Deall All,
    Thanks to all of you gurus i have been able to Get delta update for my query.
    There is one last issue how can i include changes records in my delta update when i am using numeric pointer for data selection.
    or
    It can only be doen by time stamp.
    can you explain me details of using time stamp.
    Thanks & regards,
    Gaurav Sood

    Dear Gaurav,
    Here we have three options for delta updation:
    Time Stamp:   If we want to update change in the records with respect to the time interval then this option is selected.
    Calend. Day:   If we want to update change in the records with respect to day to day basis then this option is selected.
    Numeric Pointer:  If we want to update in case of record which is completely new with respect to Field name then we use this option.
    And we have got some settings like:
    Safety Interval upper limit:
    This field is used by Data Sources that determine their delta generically using a repetitively-increasing field in the extract structure.
    The field contains the discrepancy between the current maximum when the delta or delta init extraction took place and the data that has actually been read.
    Leaving the value blank increases the risk that the system could not extract records arising during extraction.
    Example: A time stamp is used to determine the delta. The time stamp that was last read is 12:00:00. The next delta extraction begins at 12:30:00. In this case, the selection interval is 12:00:00 to 12:30:00. At the end of extraction, the pointer is set to 12:30:00.
    A record - for example, a document- is created at 12:25 but not saved until 12:35. It is not contained in the extracted data but, because of its time stamp, is not extracted the next time either.
    For this reason, the safety margin between read and transferred data must always be larger than the maximum length of time that it takes to create a record for this DataSource (with a time stamp delta), or it must display an interval that is sufficiently large (for determining delta using a serial number).
    Safety Interval Lower Limit
    This field contains the value taken from the highest value of the previous delta extraction to determine the lowest value of the time stamp for the next delta extraction.
    For example: A time stamp is used to determine a delta. The extracted data is master data: The system only transfers after-images that overwrite the status in the BW. Therefore, a record can be extracted into the BW for such data without any problems.
    Taking this into account, the current time stamp can always be used as the upper limit when extracting: The lower limit of the next extraction is not seamlessly joined to the upper limit of the last extraction. Instead, its value is the same as this upper limit minus a safety margin. This safety margin needs to be big enough to contain all values in the extraction which already had a time stamp when the last extraction was carried out but which were not read. Not surprisingly, records can be transferred twice. However, for the reasons above, this is unavoidable.
    Data Source Is Real-Time Enabled
    The 'real time enabled' indicator determines whether a delta-enabled Data Source can be used as a supplier of data for a real-time daemon.
    And there are two options provided like
    1)     New Status for changed records:
    If you select this option each record to be loaded delivers the new status for the key figures          and characteristics. DataSources with this delta type can write to ODS objects or master data tables.
    2)     Additive Delta:
    The key figures for extracted data are added up in BW. Data Sources with this delta type can supply data to ODS objects and Info Cubes.
    Hope this helps u..
    Best Regards,
    VVenkat..

  • How to overcome view changes in bdc session method  using recording ?

    how to overcome view changes in bdc session method  using recording ?
    ex-for mm01 in recording if i selected views basic data1 and basic data2.
    i seheduleded for background for after 3 days .
    if any body changes views by selecting other views also.
    how to overcome this with out programming ?
    is there any settings ?

    Hi,
    I am attaching few threads.Hope these will help you.
    If there are any error records in session, all those error records will get poulated in log .SM35 and after the session is completed , u can see error records which can be corrected and reprocessed again
    We have the structures BDCLD and BDCLM, which will capture the log details inthe session. Firstly, sesssion should be processed. After that log will be created. Then caputure the information into an internal table using BDCLM and BDCLD.
    and refer the link.
    error correction in bdc session
    regards
    Madhu

  • How we can load change record in cube.

    Hi,
         How we can load change record in cube, (delta)
         i need step by step in sap BI 7.0.

    Hi Nitin
    I hope you are asking about delta loads, if your datasource supports deltas then you can do only changed records from source to cube. To see the details goto ROOSOURCE table in ECC and find.
    For further help search in SDN and help.sap.com, you can find n number of postiings about the same.
    Thanks
    Reddy

  • We are upgrading from 8.3 to 9.2. How can i get the table(record) structure changes between these 2 version

    We are upgrading from 8.3 to 9.2. How can i get the table(record) structure changes between these 2 versions. I am not able to find it in Oracle support.

    My guess is you want to upgrade HR8.3 to 9.2 - and that is not one jump upgrade. You will need to go HRMS 83 to 90
    (PeopleSoft Enterprise HRMS 8.3x to 9.0 Upgrade (Doc ID 747333.1) and then 90 to 92 (PeopleSoft Human Capital Management 9.0 to 9.2 Upgrade Home Page (Doc ID 1536087.1)
    Each these MOS pages contains the Demo to Demo Compare Reports that show the data structures changes between the releases.
    Hope it helps.

  • How to trigger a workflow when a info record is changed?

    Hello All,
    I would like to trigger a workflow when the conditions from a info record are changed?
    What business object should be used?
    Thanks in Advance
    Rui

    Hi,
    for these kinds of issues,
    foirst check if a uefull event already exists in the system
    for this you first actiave the event trace: SWELS.
    Then you change the info record.
    And then you read the event log with SWEL.
    If there's no event, you may eventually have to create it in an exit with SAP_WAPI_CREATE_EVENT fm
    Kind regards, Rob Dielemans

  • How to use the change log in ODS to track Delta change?

    People say that historical data (like Delta change) in ODS can be tracked in the Change Log.  How to use the change log to track historic data?
    Thanks

    Kevin
    See if it helps
    Every ODS object is represented on the database by three transparent tables:
    Active data: A table containing the active data (A table)
    Activation queue: For saving ODS data records that are to be updated but that have not yet been activated. The data is deleted after the records have been activated.
    <b>Change log: Contains the change history for delta updating from the ODS Object into other data targets, such as ODS Objects or InfoCubes for example.</b>
    An exception is the transactional ODS object, which is only made up of the active data table.
    The tables containing active data are constructed according to the ODS object definition, meaning that key fields and data fields are specified when the ODS object is defined. Activation queue and change log are the same in the table’s structure. They have the request ID, package ID and the record number as a key.
    Data base structure changes
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/d53ec3efdc9b47a9502c3a4565320c/frameset.htm
    Hope this helps
    Thnaks
    Sat

  • How to catch any changes made in a particular field of a table.

    Dear Friends,
                           How can we display changes to a filed of a particular table.
    To make it simple:--
    The Program should take values for the name of the table and the field according it will handle all the update ,deletion of a record..i mean any change happening to the respective field will be displayed.
    Suppose there is table STUDENT and a field STUDENT_ID.
    So i want to display  the newly entered student id or the deleted student id .
    thx
    ram

    Hi,
    RSSCD100                 Display Change Documents
    RSSCD100_PFCG      Display Change Documents for Role Administration
    RSSCD110                 Display change documents (cross-client)
    RSSCD150                  Display change documents
    reward if useful
    ~Lakshmiraj~

  • How to Divert the changes to cdhdr table instead of dbtablog?

    Hai everybody.
    I am new to this forum. i got a job in abap recently. The below is my requirement.I want solution for this one. Anybody plz help me.
    I am having ztransaction.
    The change logs already were captured in DBTABLOG for table ZWPRFRUND (in transaction ZWPG).
    The only report which is currently used to get the change logs is RSVTPROT
    Now my requirement is,
    we need to display the change logs in the form of ALV.
    We should divert the changes to CDHDR table instead of DBTABLOG, then we can use the RSSCD100 to display change logs.
    The Important items for the change LOG needed in case of changes to table in “ZWPG” are,DATE ,TIME,USER,FIRST NAME,FILED NAME,OLD VALUE,NEW VALUE
    The above fields need to be displayed in the grid. In the above list “FIELD NAME” denotes any field of the table in the transaction in “ZWPG”
    Thanks & Regards,
    Sujatha.T.

    Check out my post in this thread:
    How to record add-on table change logs?
    You need to define a change document type and generate relevant code for this.
    Andrew

  • How to know the changes made to Quotations & Sales orders?

    Hi all
    I want to know how we can have the records of changes and alterations that are made in quotations and Sales orders. For example, once the quotation is created and saved, there must have been many alterations either on pricing or in terms & conditions based on the final negotiations with the customer. Please let me know how do we record the changes.

    Hi,
    what ashish told is exactly correct.You just go to the Environment-changes and execute,it will shows all the changes made for that order like pricing,payment terms etc.
    Regards,
    Hari.

  • How to create the change document functionality for a dependent objects?

    May I please know how to create the change document functionality for a dependent objects?
    I have done it follow the same process as for business process objects. But when i try to test it in BOBT, there is no records under "FIELD_CHANGE_WITH_FILTER". It seems the change hasn't been recorded.
    If the way I did to create change document for dependent object is correct, please also kindly advise the possibilities for why there is no record during testing.
    thanks in advance.

    I also have some doubts about the business object.In this case,one abstract BO hase a subnode wihich is root extended.I added the change document for this node under the category "root_extended" and then tested the function in BOBT.I got some error message "can't find the root key".Shall i redefine the method /BOFU/IF_CDO_CREATION~IS_CDO_CREATION_ACTIVE so as to solve the problem?
    Thx.

  • How to record menus that display when mouse hovers

    The software I am creating a training session for has
    pull-down menus that display when the mouse clicks on them or when
    the mouse hovers over them. I can only get Captivate to record the
    menus when the mouse is clicked - and cannot determine how to
    record the menus that display when the mouse hovers. Can anyone
    offer any suggestions as to how to fully capture the displayed
    software screens and menus? Thanks.

    > Thanks. The Print Screen works just OK - although it is
    a cumbersome and
    > the
    > timing is not as smooth as it could be. As I make a
    series of training
    > videos
    > over time and many menus will be missed and more retakes
    will be required.
    >
    You can change the timing yourself - just reduce the time the
    slide catch
    with print screen to a second or whatever works for you.
    Steve
    http://twitter.com/Stevehoward999
    Adobe Community Expert: eLearning, Mobile and Devices
    European eLearning Summit - EeLS
    Adobe-sponsored eLearning conference.
    http://www.elearningsummit.eu

  • How to set a change pointer for a perticular table?

    Hi,
    Please let me know how to set a change pointer for a perticular table.

    what do you mean by 'change pointer'? normally this idiom is used for sending ÍDOCs from one system/client/org-unit to another ...
    do you generally want to record changes to a specific table? then set parameter rec/client using RZ10 for your instance profiles and restart the instances in order for the parameter to take effect.
    set the table to 'record all changes' using SE11.
    you might re-consider if the table has a lot of  data and is accessed very often for performance-resons.
    change protocols can be evaluated using tx, SCU3.

  • How do we track changes done in KSH2?

    Hi Gurus,
    Some cost center in the cost center group went missing. This happens a lot for the past months. I cannot find any log that record the changes. Any idea how can I check who make the changes.
    Already considered limiting the authorization to KSH2 and use auth group. But still need to find the root cause to the missing cost center. Thanks.

    Hi
    Please try the T.Code:OKEON,
    In this Screen select your Cost Center Group, Select Basic Data
    Click on (Display Change Document) Icon in that you will get all the Changes related to Cost Center Group..

Maybe you are looking for