Query fixed for findAvailableHabitDictionaryByUser method
@@ -9,6 +9,7 @@ import org.springframework.data.repository.query.Param;
/**
* Provides an interface to manage {@link HabitDictionary} entity.
+ *
* @author Bogdan Kuzenko
*/
public interface HabitDictionaryRepo extends JpaRepository<HabitDictionary, Long> {
@@ -18,14 +19,12 @@ public interface HabitDictionaryRepo extends JpaRepository<HabitDictionary, Long
* @param user user which we use to filter.
* @return List of available {@link HabitDictionary}`s.
*/
- @Query("SELECT hd "
- + "FROM HabitDictionary hd "
- + "WHERE hd.habit "
- + "IN(SELECT h "
- + "FROM Habit h "
- + "WHERE h.statusHabit = true AND h.users "
- + "IN(SELECT u "
- + "FROM User u "
- + "WHERE u.id = ?1))")
+ @Query(nativeQuery = true, value = "SELECT hd "
+ + "FROM habit_dictionary hd "
+ + "INNER JOIN habits hb "
+ + "ON hb.habit_dictionary_id = hd.id "
+ + "INNER habits_users_assign hua "
+ + "ON hua.habit_id = hb.id "
+ + "AND hua.users_id = ?1")
List<HabitDictionary> findAvailableHabitDictionaryByUser(@Param("user") User user);
}
\ No newline at end of file
