Skip to content Skip to sidebar Skip to footer

How To Use Setbalance Method In My Entity To Set The Actual Balance Value Of A Member?

I use Android Room for my database. I have a title screen and when I click on a button there, my activity opens. The activity shows me a list of members saved in the database. My e

Solution 1:

You should probably update the balance when inserting a new transaction in the transaction_table table. You can use @Transaction to execute 2 queries in a single transaction in your DAO. Something like this should work:

@DaopublicabstractclassTransactionDao {

    // ...@TransactionpublicvoidinsertTransactionForMember(Member member, Transaction transaction) {
        insertTransaction(transaction);
        BigDecimalnewBalance= member.getBalance() + transaction.getBalance()
        member.setBalance(newBalance);
        updateMember(member); // implement it here or 
    }

}

Now this answer is not ideal. TransactionDao should not contain a method to update member. You should have a repository handle this, call 2 insert methods on 2 DAOs inside a transaction. Also, I don't see a foreign key from Transaction to Member. Adding one might be a good idea

Solution 2:

Post a Comment for "How To Use Setbalance Method In My Entity To Set The Actual Balance Value Of A Member?"