I have a Spring boot application with below entity
@Entity
public class Transaction {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID transactionID;
private Long fromAccount;
private Long toAccount;
private Double amount;
private Double balance;
@Column(name = "timestamp", columnDefinition = "TIMESTAMP WITH TIME ZONE")
private OffsetDateTime timestamp;
}
When I save this transaction to PostgreSQL table it correctly saves the data with timezone offset.
amount | balance | from_account | timestamp | to_account | transactionid
--------+---------+--------------+----------------------------------+------------+--------------------------------------
200 | 200 | 2 | 2024-04-25 02:15:30.570947+05:30 | | a36114a7-ac90-42b1-adec-c910d5685330
But when I try to retrieve the transaction using findAllByFromAccountOrderByTimestampAsc(accNo)
. The timestamp does not contain the offset anymore.
{
"transactionID": "a36114a7-ac90-42b1-adec-c910d5685330",
"fromAccount": 2,
"toAccount": null,
"amount": 200.0,
"balance": 200.0,
"timestamp": "2024-04-24T20:45:30.570947Z"
}
I want to store the timestamp with server’s timezone.
What am I doing wrong here ?