Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate not sorting results #10

Open
DimaStoyanov opened this issue Mar 24, 2018 · 0 comments
Open

Hibernate not sorting results #10

DimaStoyanov opened this issue Mar 24, 2018 · 0 comments
Assignees
Labels
question Further information is requested
Milestone

Comments

@DimaStoyanov
Copy link
Owner

In game entity fields playerStates and field has annotation @OrderBy. If insert and read game using controllers, this fields will be sorted. But in test it doesn't work

    @Before
    @Transactional
    public void insert(){
        Player john = new Player("john");
        Player ivan = new Player("ivan");
        Player alisa = new Player("alisa");
        Player bot = new Player("bot");
        List<Player> players = Arrays.asList(john, ivan, alisa, bot);

        List<CellState> cellStates = Arrays.asList(new CellState(2), new CellState(1),
                new CellState(0), new CellState(3));

        List<PlayerState> playerStates = Arrays.asList(new PlayerState(200, 0, john),
                new PlayerState(200, 2, alisa),
                new PlayerState(200, 1, ivan),
                new PlayerState(200, 3, bot));

        List<Game> games = Arrays.asList(new Game(playerStates, john, cellStates),
                new Game(playerStates, alisa, cellStates));


        playerRepository.saveAll(players);
        gameRepository.saveAll(games);

    }
    @Test
    @Transactional
    public void checkSort(){
        gameRepository.findAll().forEach(g -> {
            ArrayList<Integer> positions = new ArrayList<>();
            g.getField().forEach(c -> positions.add(c.getPosition()));
            Assert.assertEquals(Arrays.asList(0, 1, 2, 3), positions);
        });

        gameRepository.findAll().forEach(g -> {
            ArrayList<Integer> orders = new ArrayList<>();
            g.getPlayerStates().forEach(p -> orders.add(p.getOrder()));
            Assert.assertEquals(Arrays.asList(0, 1, 2, 3), orders);
        });
    }

And get next output:

java.lang.AssertionError: 
Expected :[0, 1, 2, 3]
Actual   :[2, 1, 0, 3]
@DimaStoyanov DimaStoyanov added the question Further information is requested label Mar 24, 2018
@DimaStoyanov DimaStoyanov added this to the dev milestone Mar 24, 2018
@DimaStoyanov DimaStoyanov self-assigned this Mar 24, 2018
@DimaStoyanov DimaStoyanov added this to To do in Project plan via automation Mar 24, 2018
@DimaStoyanov DimaStoyanov removed this from To do in Project plan Apr 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant