0
org.hibernate.query.QueryTypeMismatchException: Specified result type [java.lang.String] did not match Query selection type [com.ssafy.ssap.domain.qna.ArticleImage] - multiple selections: use Tuple or array
@Repository
public interface ArticleImageRepository  extends JpaRepository<ArticleImage, Integer> {
    List<String> findAllImagePathByQuestionId(Integer questionNo);
    List<String> findAllImagePathByAnswerId(Integer answerNo);
}

try{
            switch(pattern){
                case "question" -> urlList = articleImageRepository.findAllImagePathByQuestionId(id);
                case "answer" -> urlList = articleImageRepository.findAllImagePathByAnswerId(id);
                default -> throw new NullPointerException();
            }
            resultMap.put("urlList",urlList);
            return resultMap;
        }catch(NullPointerException e){

same errors' occuring at AlarmRepository so i thought it's something Structual Mistake I can solve it with just using Entity by using 'findById(id)' method, but i want to know what problem is.

error message is saying my 'repository.findBy~' method(or query) is returning Class Entity(not column Entity) but i can't find any mistakes i've done on JPA grammar. (and it occurs twice same) please let me know to improve more Thank YOU

i did change return type of repository method to String[] but it also did not work

adding my Domain Class

     @Column(name = "image_path")
     @Lob
     private String imagePath;
DGun
  • 1
  • 1
  • check this out https://stackoverflow.com/questions/22007341/spring-jpa-selecting-specific-columns – rahulP Aug 11 '23 at 16:13

1 Answers1

0

Spring query generation has limits, and is building you a query to return Entity instances, not String imagePath value you expect.

Define the query yourself with JPQL using something like:

@Repository
public interface ArticleImageRepository  extends JpaRepository<ArticleImage, Integer> {
    @Query(value = "SELECT image.imagePath FROM ArticleImage image where image.questionId = :questionNo")
    List<String> findAllImagePathByQuestionId(Integer questionNo);
    @Query(value = "SELECT image.imagePath FROM ArticleImage image where image.answerId = :answerNo")
    List<String> findAllImagePathByAnswerId(Integer answerNo);
}
tremendous7
  • 721
  • 6
  • 9
Chris
  • 20,138
  • 2
  • 29
  • 43
  • Thank you! and i want to know why does it happen. Is it just unexpectable functional error? – DGun Aug 12 '23 at 08:29
  • You'd have to go through the docs and code (I don't know it well enough), but guess it is a feature they haven't implemented. – Chris Aug 13 '23 at 15:36