1

How do include a function like getdate() in an insert statement for Hibernate query?

Lets say one of the properties of a mapped class is a datetime column how do put specify getdate() in order for the .save() method call to use the server timestamp?

0

1 Answer 1

1

Simple answer is don't include it in the insert statement and let SQL do it.

In the SQL table designer where you have the date column you are inserting into, set the Default Value to GETDATE() in the column properties and SQL Server will handle it for you.

Reference and sample: SQL Server GETDATE() Function

Table create script will look like this:

CREATE TABLE Orders
(
    OrderId int NOT NULL PRIMARY KEY,
    ProductName varchar(50) NOT NULL,
    OrderDate datetime NOT NULL DEFAULT GETDATE()
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.