Announcement Announcement Module
Collapse
No announcement yet.
Customizing Auditing Entities Columns Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Customizing Auditing Entities Columns

    Hi,

    I am impressed with Spring Data JPA and I started to replace our application DAL to Spring Data. While migrating I am facing couple of issues and need an expert advice.
    Query 1: Our operational entities have auditable columns and it is named as CREATED_BY_USER_ID, LAST_UPDATED_BY_USER_ID, CREATED_DTTM, LAST_UPDATED_DTTM. I tried the following annotation at entity level but it is not helped.
    Code:
    @AttributeOverrides({
    	@AttributeOverride(name="createdBy", column=@Column(name="CREATED_BY_USER_ID")),
    	@AttributeOverride(name="lastModifiedBy", column=@Column(name="LAST_UPDATED_BY_USER_ID")),
    	@AttributeOverride(name="createdDate", column=@Column(name="CREATED_DTTM")),
    	@AttributeOverride(name="lastModifiedDate", column=@Column(name="LAST_UPDATED_DTTM"))
    })
    public class ExtendedAbstractAuditable<U, PK extends Serializable> extends AbstractAuditable<U, PK> {
    
    }
    Query 2: How to change/override the primary key value generation strategy. I am looking to change the generate value strategy as UUID for my application.

  • #2
    I solved the issue Wrote a custom AbstractAuditable class.. thats all...

    Code:
    @MappedSuperclass
    @Access(AccessType.FIELD)
    public class AbstractAuditable<U, PK extends Serializable> implements
    		Auditable<U, PK> {
    
    	private static final long serialVersionUID = -7110939966468361300L;
    
    	@Id
    	@GeneratedValue(generator = "system-uuid")
    	@GenericGenerator(name = "system-uuid", strategy = "uuid")
    	private PK id;
    
    	@Basic
    	@JoinColumn(name = "CREATED_BY_USER_ID", nullable = true, updatable = false)
    	@ManyToOne
    	private U createdBy;

    Comment

    Working...
    X