I had similar problem with my native query.
The jsonb field name is called data, and it's simple
{
"name" : "genderList",
"displayName" : "gender list"
}
I want to find by name with JpaRepository, and here is my Repository
@Repository
public interface LookupListRepository extends JpaRepository<LookupList, UUID>
{
@Query(value = "SELECT * FROM lookup_list WHERE data->>'name' = :name",
nativeQuery = true)
List<LookupList> findByName(@Param("name") String name);
}
You need nativeQuery = true.
With nativeQuery = true, this works as well.
SELECT * FROM lookup_list WHERE jsonb_extract_path_text(data, 'name') = :name
I see your @Transactional annotation, I assume you have the native query on top of application service method. Can you try moving all native query's in repository and use JpaRepository, and use the repository method in your application service?
Here is how my application service uses the repository.
public class LookupListServiceImpl implements LookupListService
{
@Autowired
LookupListRepository lookupListRepository;
@Override
@Transactional
public void changeLookupList(LookupListDto lookupListDto)
{
List<LookupList> lookupLists = lookupListRepository.findByName(lookupListDto.getName());
...
}
}
Reference for JPA repository
http://docs.spring.io/spring-data/jpa/docs/1.3.0.RELEASE/reference/html/jpa.repositories.html