Reputation: 567
For example I have 2 tables: table1 = book, table2 = site --> 1 book can have n sites.
<entity name="book" dataSource="myDs" pk="id"
transformer="TemplateTransformer"
query="SELECT b.id, b.title, s.id, s.number, s.content
FROM book b. site s WHERE b.id = s.book">
<field column="b.id" name="id" />
<field column="s.id" name="sId" />
<field column="id" template="${id}_${sId}" ignoreMissingVariables="true" />
</entity>
Why this dont work? I just get only 1 book with 1 site as result and not x book with x sites I just dont get a compound key in field 'id'.
Upvotes: 1
Views: 425
Reputation: 21
I recently ran into similar issue and following points fixed it for me:
i was doing above against Oracle DB. Not 100% sure if it applies to other DB but wanted to share the solution.
Here is an attempt to re define your DIH with the above changes
<entity name="book" dataSource="myDs" pk="id"
transformer="TemplateTransformer"
query="SELECT b.id, b.title, s.id as sid, s.number, s.content
FROM book b. site s WHERE b.id = s.book">
<field column="sid" name="sid" />
<field column="id" template="${book.ID}_${book.SID}"/>
</entity>
Upvotes: 2
Reputation: 567
yes I deleted the index and inserted him new.
what I get:
<doc>
<str name="id">1</str>
<str name="title">Im a title</str>
<str name="number">1337</str>
<str name="content">content 23</str>
</doc>
what I want:
<doc>
<str name="id">1_1</str>
<str name="title">Im a title</str>
<str name="number">1337</str>
<str name="content">content 23</str>
</doc>
<doc>
<str name="id">1_2</str>
<str name="title">Im a title for 2</str>
<str name="number">1654654</str>
<str name="content">ekddsd</str>
</doc>
I already tried to change following
<field column="id" template="${id}_${sId}" ignoreMissingVariables="true" />
into
<field column="id" template="${id}_${someOtherField}" ignoreMissingVariables="true" />
and the result didn't change.. Looks like the TemplateTransformer doesn't work?
EDIT Found something in my logs:
Unable to resolve variable: id while parsing expression: ${id}_${sId}
Unable to resolve variable: sId while parsing expression: ${id}_${sId}
Upvotes: 0
Reputation: 26032
Add multivalued=true to the id and sId fields in schema.xml file.
Upvotes: 0