I am facing date time issue in my spring boot jpa application.
For example, In my database I have one column created_on
which contains 2019-07-11 09:30:00
date.
When I fetch this record threw JPA it converts to UTC.
Means date 2019-07-11 09:30:00
converts to 2019-07-11 05:00:00
.
My System time is in IST and date is saved in database in IST as well.
I am using mysql database.
In my Enitity
private Date createdOn;
Database column:
created_on timestamp
Service:
@Service
@Transactional(readOnly = true)
public class EntityTypeService {
@Autowired
private IEntityTypeRepository entityTypeRepository;
public EntityType findById(Long id) {
EntityType entityType = entityTypeRepository.findById(id).orElse(new EntityType());
System.out.println(entityType.getCreatedOn());
return entityType;
}
}
Repository
@Repository
public interface IEntityTypeRepository extends CrudRepository<EntityType, Long> {
}
Date in database is 2019-07-11 09:30:00
But when I print it on service System.out.println(entityType.getCreatedOn());
it gives me 2019-07-11 05:00:00
.
This is generic issue in my whole application.