Distinct values on view screen

Hi,

I had created Entity List view screen and i am trying to pass distinct values to the screen.
Table Structure is Id , name , Authorise but since id is identity insert value due to which name and authorise are not getting distinct. If i try with DTO i will have to add additional logic for Pagination.

Jmix 2.0

Hi,

To solve the issue with duplicate entries, you could create a database view that selects the DISTINCT values directly within the database. This approach allows you to use a “View-Only Entity” in Jmix without needing additional DTOs or pagination logic.

Here’s an example of how the SQL statement could look in a Liquibase script:

<changeSet id="create-distinct-view" author="yourName">
    <createView viewName="distinct_values_view" replaceIfExists="true">
        SELECT DISTINCT name, authorise 
        FROM your_table
    </createView>
</changeSet>

Once the view is created, you can define a new entity in Jmix, specifically for reading this view. Use @JmixEntity and @Table(name = “distinct_values_view”) and in particular @DbView in the view entity class to refer to the database view. You can find more details in the Jmix documentation on View-Only Entities: Entities :: Jmix Documentation

This should allow you to display only the unique combinations of name and authorise in your screen.

Cheers