Wednesday, 25 May 2016

createBy Null

In Hibernate POJO for createdBy field add updatable=false in @Column annotation

@Column(name ="CreatedBy", updatable=false)
private BigInteger createdBy;




For createdDate and ModifiedDate you can write triggers.
No need to write even createddate and modified date fields in Hibernate POJO.


CREATE TRIGGER tr[TableName]CreateDate ON [TableName]
FOR INSERT
AS
UPDATE [TableName] SET [TableName].Created=getdate()
FROM [TableName] INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID]

GO

CREATE TRIGGER tr[TableName]LastModifiedDate ON [TableName]
FOR UPDATE
AS
UPDATE [TableName] SET [TableName].LastModified=getdate()
FROM [TableName] INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID]

No comments:

Post a Comment