Skip to main content

Posts

Showing posts from March, 2017

Dealing with Java's LocalDateTime in JPA

A few days ago I ran into a problem while dealing with a LocalDateTime attribute in JPA. In this blog post I will try to create a sample problem to explain the issue, along with the solution that I used. Consider the following entity, which models an Employee of a certain company - @Entity @Getter @Setter public class Employee { @Id @GeneratedValue private Long id; private String name; private String department; private LocalDateTime joiningDate; } I was using Spring Data JPA, so created the following repository - @Repository public interface EmployeeRepository extends JpaRepository<Employee, Long> { } I wanted to find all employees who have joined the company at a particular date. To do that I extended my repository from JpaSpecificationExecutor - @Repository public interface EmployeeRepository extends JpaRepository<Employee, Long>, JpaSpecificationExecutor<Employee> { } and wrote a query like below - @SpringBootTest