0

Author (Cursor 1 Data)

ID NAME PUBLISH_ID
1 John 123
2 Jane 345

Book (Cursor 2 Data)

PUBLISH_ID BOOK_ID BOOK_NAME
123 B101 C#
123 B102 Python
345 J001 SQL
345 J002 JAVA
Class Author {
  String Id
  String authName;
  List<Books> books
}

Class Books {
   int publishId;
   int bookId;
   String bookName;
}

Question: how can it be mapped so that author can have only their books and want to display each author with their own books only?

I tried: there are two separate cursors Author and Books. I will have to use mybatis xmlconfig mapper. I can't use a query to achieve only mybatis mapper config xml

Map I tried shown here doesn't work:

<resultMap id="authorMap type="demo.Author">
  <id property="Id" column="Id"></id>
  <collection property="Books" column="publishId" type="ArrayList" resultMap="booksMap" />
</resultMap>
<resultMap id="booksMap" type="demo.Books">
  <result property="publishId" column="publish_id"/>
  <result property="bookId" column="book_id"/> 
</resultMap>

I'm expecting to map base on publish id so each author only their multiple books.

   Id:1
   authNm: John
   Email: John@g.com
   book:
     publishId: 123,
     bookId: B101

     publishId: 123,
     bookId: B102

   Id:2
   authNm:Jane
   book:
    publishId: 345,
    bookId: J001

    publishId: 345,
    bookId: J002`
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • MyBatis supports this ([see](https://github.com/harawata/mybatis-issues/tree/master/so-59543132) how it works with MS SQL Server), however, there seems to be a bug in the Oracle driver and I couldn't make it work (tested with version 23.2.0.0). In case someone can report the issue to Oracle, [here](https://gist.github.com/harawata/66ccb4189d0e21a5eb9e383c52695523) is the plain JDBC code that reproduces the issue (see the comment for the details). – ave Apr 16 '23 at 07:35
  • For some reason, I assumed that you are using Oracle. If that is not the case, please add the information about the DB/driver to the question. – ave Apr 16 '23 at 07:55
  • @ave Thanks for your response and yes you're correct i am using Oracle 21.3.0.0 for ojdbc8 – QuestForKnowledge Apr 16 '23 at 13:31
  • Then, my first comment still stands. It will work once the driver issue is resolved (please report it if you can). FYI, you can get the cursors as independent `List`s via `OUT` parameters like [this](https://github.com/harawata/mybatis-issues/blob/bca364d6a42571b34d9508992113e7ca145b1001/so-56834806/src/test/resources/test/Mapper.xml#L21), however, you may have to 'join' these lists by yourself. – ave Apr 16 '23 at 15:58

0 Answers0