I am currently working on my first java project and have jumped into using spring/hibernate.
I have created a of API's which is used to perform CRUD operations on a database. I thought it would be a good idea to write the current time an item is added to the database.
To do this this I created a new column in the database & updated the entity I am using to write to it, with a new javafield called "timestamp" & mapped it to the database column.
I then used (or tried to) the below code to have the system set the timestamp as the item is written into the db as I am doing something similar to ensure the id is set to 0 before it auto increments.
for (Downloads tempDownload : theDownloads) {
// display the download
tempDownload.setId(0);
tempDownload.setTimestamp(System.currentTimeMillis());
System.out.println(tempDownload);
// save to the database
downloadsService.saveProduct(tempDownload);
}
However when the item is written to the db the timestamp is written as 0. if I remove the
tempDownload.setTimestamp(System.currentTimeMillis());
then I am able to set the time via json by manually passing it in with the payload. Is there another way to go about this, or a step I could be missing?
Kind regards,
Danny