ホームページ  >  に質問  >  本文

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类)
有大神知道对么?

迷茫迷茫2742日前822

全員に返信(1)返信します

  • 伊谢尔伦

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

    ここで報告されたエラーは、クエリ ステートメントが Object[] 配列を返したというものです。JPA はそれをカスタム オブジェクトに変換しようとしましたが、失敗しました。次の方法を試してください。

    1. select new + オブジェクトの完全なクラス名の構文を使用します。

      ここで、Perso は EntityManager によって管理されるエンティティであり、PersonResult はカスタム エンティティです
      リーリー

    2. データを受け取るには Object[] 配列を使用します。 Object[] の各要素の値は、対応する列の値です。 リーリー

    3. まず、Java コードを使用して Person を検索し、それを PersonResult に変換します
    4. 返事
      0
  • キャンセル返事