DimaStoyanov / Monopoly

Board game implementation
https://monopoly-in-map.herokuapp.com/
MIT License
0 stars 1 forks source link

PostPresist not update entity #1

Closed DimaStoyanov closed 6 years ago

DimaStoyanov commented 6 years ago

I added this code in Score entity, so I want to update PlayerStat entity every time I save Score entity.

   @PostPersist
    void updatePlayerStat(){
        System.out.println("On score post persist");
        player.getStat().incrementTotalGames();
        player.getStat().setTotalScore(player.getStat().getTotalScore() + score);
        System.out.println(player);
    }

and this code in Game entitiy

    @PostPersist
    private void update(){
        System.out.println("On game post persist");
        winner.getStat().incrementTotalWins();
    }

So, after insert single Player, Game and Score both event listener triggers and has output like this

On game post persist
On score post persist
Player(createdAt=2018-03-14, nickname=Anonymous,  
 stat=PlayerStat(totalScore=100, totalWins=1, totalGames=1), scores=null) 

But when I try to read this user in seperate request, I got next output:

Player(createdAt=2018-03-14, nickname=Anonymous,  
 stat=PlayerStat(totalScore=0, totalWins=1, totalGames=0), scores=[Score(score=100)])

So Game event listener update PlayerStat, but Score event listener doesn't

DimaStoyanov commented 6 years ago

https://stackoverflow.com/a/49280241/7065411