Skip to content
Advertisement

With MyBatis. How can I map two different records in one table, then construct a single query result when joining that table?

The definition of my query result entity has two fields, origin and destination, which are both Location type, and I’m trying to fetch the information in location table with JOINS.Here are the resultMap definition and SQL:

JavaScript

SQL:

JavaScript

It is supposed that the origin and destination are different records, however I found that origin and destination turned out to be same…

Can anybody please tell me how to fix it or where is the problem?

I’m using MyBatis 3.2.2 and MS SQL Server 2008 R2.

Advertisement

Answer

When the result list contains columns with the same name, you will need to provide an alias for at least one of the columns. For example:

JavaScript

SQL:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement