001    package org.kuali.student.common.entity;
002    
003    import javax.persistence.Column;
004    import javax.persistence.Id;
005    import javax.persistence.MappedSuperclass;
006    import javax.persistence.PrePersist;
007    import javax.persistence.PreUpdate;
008    import javax.persistence.Version;
009    
010    import org.kuali.student.common.util.UUIDHelper;
011    
012    @MappedSuperclass
013    public abstract class BaseEntity {
014            
015            @Id
016            @Column(name = "ID")
017            private String id;
018            
019            @Version
020            @Column(name="VER_NBR")
021            private Long versionNumber;
022            
023            @Column(name="OBJ_ID",length=KSEntityConstants.OBJ_ID_LENGTH)
024            private String objectId;
025            
026            public String getObjectId() {
027                    return objectId;
028            }
029    
030            public void setObjectId(String objectId) {
031                    this.objectId = objectId;
032            }
033    
034            @PrePersist
035            public void prePersist(){
036                    //Auto generate the object id, and auto generate the ID if it's not set 
037            this.id = UUIDHelper.genStringUUID(this.id);
038                    this.objectId = UUIDHelper.genStringUUID();
039                    onPrePersist();
040            }
041            
042            @PreUpdate
043            public void preUpdate(){
044                    onPreUpdate();
045            }
046            
047    
048            //Override this to add additional functionality for the PrePersist Lifecycle
049            protected void onPrePersist() {
050            }
051            
052            //Override this to add additional functionality for the PreUpdate Lifecycle
053            protected void onPreUpdate() {
054            }
055            
056            public Long getVersionNumber() {
057                    return versionNumber;
058            }
059    
060            public void setVersionNumber(Long versionNumber) {
061                    this.versionNumber = versionNumber;
062            }
063    
064            public String getId() {
065                    return id;
066            }
067    
068            public void setId(String id) {
069                    this.id = id;
070            }
071    
072    }