Skip to content
Advertisement

Retrieving a list of values across databases with mybatis

I have 2 Java POJO files

JavaScript
JavaScript

The database has a FK mapping between FilterVariable.id and ValueVariable.valueListId. Inserts into the table work perfectly, i have a single transaction that inserts into both tables separately. While retrieving the data using select and join, I only receive the first row from the table in the database.

Database Tables:

JavaScript
JavaScript

The method in the interface is defined as List<FilterVariables> selectFilterVariableById(String id); I understand that with 2 separate I can store values into the two Pojo and use them, but is there any way with joins where I can retrieve multiple rows?

The result map is defined as so:

JavaScript

This is how the data in mysql looks like. enter image description here

When a request is made from Java:

JavaScript

I only get the first row

[FilterVariables [id=b218df5c-eac1-4e01-846a-119345bb254d, name=ME, valueId=null, storageRecordType=null, values={b218df5c-eac1-4e01-846a-119345bb254d test@mailinator.com}]]

1

Advertisement

Answer

As mentioned by @ave, the solution is to either

  1. Remove the from the collection – degrades performance
  2. Just rename the variable used in – Implementation below:

The result map is now:

JavaScript

With this the results come as required.

ValueVariable is now:

JavaScript

The select query is now:

JavaScript

Please note that VV.id is to be aliased for this to work.

Advertisement