Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix a bug which affects LocalDate/LocalTime related queries
  • Loading branch information
Hung Tran committed May 4, 2021
commit df511f58538d158e2a5eff320a3da4e72611c0b8
11 changes: 4 additions & 7 deletions webapi/src/integration-test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ spring:

logging:
level:
org:
springframework:
test:
context:
jdbc:
SqlScriptsTestExecutionListener:
DEBUG
org.hibernate.SQL: OFF
org.hibernate.type: OFF
org.springframework:
test.context.jdbc.SqlScriptsTestExecutionListener: DEBUG
3 changes: 2 additions & 1 deletion webapi/src/main/java/com/mealtracker/config/JpaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableAutoConfiguration
@EntityScan(basePackages = {"com.mealtracker.domains"})
@EntityScan(basePackages = {"com.mealtracker.domains"}, basePackageClasses = { Jsr310JpaConverters.class })
@EnableJpaRepositories(basePackages = {"com.mealtracker.repositories"})
@EnableTransactionManagement
public class JpaConfig {
Expand Down
4 changes: 2 additions & 2 deletions webapi/src/main/java/com/mealtracker/domains/Meal.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class Meal implements Ownable {
@Column(name = "name")
private String name;

@Column(name = "consumed_date", nullable = false)
@Column(name = "consumed_date", nullable = false, columnDefinition = "DATE")
private LocalDate consumedDate;

@Column(name = "consumed_time", nullable = false)
@Column(name = "consumed_time", nullable = false, columnDefinition = "TIME")
private LocalTime consumedTime;

@Column(name = "calories", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface MealRepository extends PagingAndSortingRepository<Meal, Long> {

List<Meal> findMealByConsumedDateAndConsumerAndDeleted(LocalDate date, User consumer, boolean deleted);

@Query("SELECT meal FROM Meal meal WHERE meal.consumer.id = :consumerId AND deleted = false " +
@Query("SELECT meal FROM Meal meal WHERE meal.consumer.id = :consumerId AND meal.deleted = false " +
"AND (:fromDate IS NULL OR :fromDate <= meal.consumedDate) " +
"AND (:toDate IS NULL OR :toDate > meal.consumedDate) " +
"AND (:fromTime IS NULL OR :fromTime <= meal.consumedTime) " +
Expand All @@ -37,7 +37,6 @@ Page<Meal> filterMyMeals(@Param("consumerId") long consumerId,
@Param("toTime") LocalTime toTime,
Pageable pageable);


@EntityGraph(value = "Meal.consumer", type = EntityGraph.EntityGraphType.LOAD)
@Query("SELECT meal FROM Meal meal JOIN meal.consumer consumer " +
"WHERE meal.deleted = false AND consumer.deleted = false AND meal.id = :mealId " +
Expand Down
Loading