Soak the beans in water overnight. Boil in the same water in a covered pan for around ten minutes. Drain using a sieve, then rinse. Preheat oven to 175°C (350°F, gas mark 4 – fan-assisted 155°C). Peel and chop onions.
Fry the bacon in a pan, then remove. Stew the onions in the bacon fat, add beans. Put beans and onions in an ovenproof dish. Bring 500 ml water to the boil in a saucepan. Add sugar, tomato purée, mustard, ginger, vinegar, salt and pepper. Boil, stirring occasionally. Pour over the beans, mix well.
Cover dish and cook in oven for around three hours. Add water if necessary. Serve with rosemary and bacon.