Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6102503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:37:18+00:00 2026-05-23T13:37:18+00:00

In my JSF web application, I use EclipseLink Descriptor Customizer and History Policy to

  • 0

In my JSF web application, I use EclipseLink

Descriptor Customizer

and

History Policy

to populate a history table in database.
The corresponding JPA entity class is annotated with @Customizer(beans.HistoryLesionhCustomizer.class)

The history table has the same fields as the source table, plus two fields (start_date & end_date) to specify the start and end of operation on a row.
It is fully working. But what I need is to populate another field in the history table.
This field I called user, should be populated with the User Principals, and this will allow me to trace the user who performed the CUD (Create/Update/Delete) operation.
I thought History Policy would allow me to add a field by just indicating its corresponding name in the database and indicate the object value that must be inserted. But that is not the case, or may it be I am not able to figure how this can be done.
In other words, along with start_date and end_date, i want to populate user field with :

FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();

package beans;

/**
 * Whenever there is a change on a record or an insert, change will be traced.
 * @author mediterran
 * 
 */
import javax.faces.context.FacesContext;
import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.history.HistoryPolicy;

public class HistoryLesionhCustomizer implements DescriptorCustomizer {

    @Override
    /**
     * Implementation method to use
     */
    public void customize(ClassDescriptor cd) throws Exception {
        String user = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();


        HistoryPolicy policy = new HistoryPolicy(); // Instantiates a new policy
//policy.postUpdate();
        policy.useDatabaseTime(); // Use the default database time to avoid date conflict
        policy.addHistoryTableName("history_lesionh"); // Indicate the source table name
        policy.addStartFieldName("start_date"); // indicate the start date DB column
        policy.addEndFieldName("end_date"); // Indicate the end date DB column
        cd.setHistoryPolicy(policy); // Use the Policy for the entity class where used @Customizer(HistoryLesionhCustomizer.class)



    }
}

Any help or workarounds would be appreciated.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:37:18+00:00Added an answer on May 23, 2026 at 1:37 pm

    Unfortunately HistoryPolicy only adds start and end date. But you can add user information to your entity with the help of an EntityListeners . Here is an example. It will add user information to each persist/update of the customer table:

    import javax.persistence.EntityListeners;
    
    @Entity
    @EntityListeners(AuditListener.class)
    @Table(name = "customer")
    public class Customer implements Serializable {
      @Column(name = "User")
      private String user;
      // getter and setter
    }
    

    and the AuditListener:

    import javax.persistence.PrePersist;
    import javax.persistence.PreUpdate;
    //...
    
    public class AuditListener {
        @PrePersist
        @PreUpdate
        public void setUserInformation(Object entity) {
            if (entity instanceof Customer) {
                Customer myEntity = (Customer) entity;
                myEntity.setUser(FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());
    
            }
        }
    }
    

    If you have more than one column that needs user information, you can use a MappedSuperclass entity and put the user column in this class. Then let all your auditable entities extend this MappedSuperclass and check in the AuditListener if the entity is an instance of the superclass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a JSF web application. I use Beans as Spring Beans (not JSF
I have a Java-JSF Web Application on GlassFish, in which I want to use
For a web application I make use of JSF 1.2 and Facelets. The problem
I am developing a JSF web application on a Windows box using Emacs as
I'm trying to use CDI for my JSF/Java EE application. I have the following
My JSF web application uses PrimeFaces Captcha. It works properly under Firefox and IE,
I followed this tutorial to configure an application (generated by seam-gen) to use eclipselink
I have web application wich uses jsf 2.0 and spring 3.0 The problem is
I am developing a web application that uses JSF 1.2 for the view layer.
I have got a web application which is speparated in a GUI (JSF 2.0,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.