찾다

 >  Q&A  >  본문

java - Jpa返回对象必须是与Entity类么?

  @Query(value = "SELECT id as topicId,content FROM bbs_topic WHERE create_time BETWEEN ?1 AND ?2",nativeQuery = true)
    List<IndexObject> getBbsTopicListByDate(Date fileupdateDate, Date topiclastupdate);

其中IndexObject 是显示层vo。
然后报错

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type [com.wayne.common.lucene.entity.IndexObject] for value '{59, 再发表一次看看那}'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [com.wayne.common.lucene.entity.IndexObject]

度娘了一下
怀疑 jpa返回对象必须是与Entity类相关(Entity就是配置了Java类与数据库映射的Java类)
有大神知道对么?

迷茫迷茫2882일 전885

모든 응답(1)나는 대답할 것이다

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:58:32

    여기서 보고한 오류는 쿼리 문이 Object[] 배열을 반환했다는 것입니다. Jpa가 이를 사용자 정의 개체로 변환하려고 시도했지만 다음 방법을 시도해 볼 수 있습니다.

    1. select new + 객체의 전체 클래스 이름 구문을 사용합니다.
      여기서 Perso는 EntityManager가 관리하는 엔터티이고 PersonResult는 사용자 지정 엔터티입니다.

      으아악
    2. Object[] 배열을 사용하여 데이터를 받습니다. Object[]의 각 요소 값은 해당 열의 값입니다

      으아악
    3. 먼저 Person을 찾아 Java 코드를 사용하여 PersonResult로 변환

    회신하다
    0
  • 취소회신하다