亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - Jpa返回對(duì)象必須是與Entity類么?
迷茫
迷茫 2017-04-18 10:56:32
0
1
907
  @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。
然后報(bào)錯(cuò)

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type [com.wayne.common.lucene.entity.IndexObject] for value '{59, 再發(fā)表一次看看那}'; 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返回對(duì)象必須是與Entity類相關(guān)(Entity就是配置了Java類與數(shù)據(jù)庫(kù)映射的Java類)
有大神知道對(duì)么?

迷茫
迷茫

業(yè)精于勤,荒于嬉;行成于思,毀于隨。

reply all(1)
伊謝爾倫

The error you reported here is that the query statement returned an Object[] array. Jpa tried to convert it into your custom object, but failed. You can try the following method:

  1. Use the syntax of select new + the full class name of the object,
    Here Perso is the entity managed by EntityManager, and PersonResult is the custom entity

    @Query(select new com.xx.yy.PersonResult(p.id,p.name,p.age) from Person p)
     List<PersonResult> findPersonResult();
  2. Use Object[] array to receive data. Each element value in Object[] is the value of the corresponding column

    @Query(select p.id,p.name,p.age from Person p)
     List<Object[]> findPersonResult();
  3. First find Person and convert it into PersonResult using java code

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template