Do it in two phases:
Phase 1:
get the monthly sales from the DB
if it does not exist {
try {
create it
persist it
flush
} catch(exception when already exists) {
// ignore
}
} else {
flush
}
Phase 2 in a transaction:
get the monthly sales from the DB
lock it
update it
commit